Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
7cb2a9ff
Commit
7cb2a9ff
authored
Oct 21, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improc ass4: Source code cleanup.
parent
3ce74ceb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
25 deletions
+30
-25
improc/ass4/canny.py
improc/ass4/canny.py
+25
-25
improc/ass4/gauss.py
improc/ass4/gauss.py
+5
-0
No files found.
improc/ass4/canny.py
View file @
7cb2a9ff
...
@@ -7,7 +7,7 @@ from gauss import Gauss1, gD
...
@@ -7,7 +7,7 @@ from gauss import Gauss1, gD
def
in_image
(
p
,
F
):
def
in_image
(
p
,
F
):
"""Check if given pixel coordinates p are within the bound of image F."""
"""Check if given pixel coordinates p are within the bound of image F."""
return
p
[
0
]
>=
0
and
p
[
1
]
>=
0
and
p
[
0
]
<
F
.
shape
[
0
]
and
p
[
1
]
<
F
.
shape
[
1
]
return
0
<=
p
[
0
]
<
F
.
shape
[
0
]
and
0
<=
p
[
1
]
<
F
.
shape
[
1
]
def
canny
(
F
,
s
,
Tl
=
None
,
Th
=
None
):
def
canny
(
F
,
s
,
Tl
=
None
,
Th
=
None
):
"""Apply the Canny Edge Detection algorithm with Gauss scale s to an
"""Apply the Canny Edge Detection algorithm with Gauss scale s to an
...
@@ -28,24 +28,24 @@ def canny(F, s, Tl=None, Th=None):
...
@@ -28,24 +28,24 @@ def canny(F, s, Tl=None, Th=None):
p
=
(
y
,
x
)
p
=
(
y
,
x
)
# Gradient norm and rounded angle
# Gradient norm and rounded angle
G
[
p
]
=
norm
(
append
(
G
x
[
p
],
Gy
[
p
]))
G
[
p
]
=
norm
(
append
(
G
y
[
p
],
Gx
[
p
]))
A
[
p
]
=
int
(
round
(
arctan2
(
Gy
[
p
],
Gx
[
p
])
*
4
/
pi
+
1
))
%
4
A
[
p
]
=
int
(
round
(
arctan2
(
Gy
[
p
],
Gx
[
p
])
*
4
/
pi
+
1
))
%
4
# Non-maximum suppression
# Non-maximum suppression
E
=
zeros
(
F
.
shape
)
E
=
zeros
(
F
.
shape
)
for
x
in
xrange
(
F
.
shape
[
0
]):
for
y
in
xrange
(
F
.
shape
[
0
]):
for
y
in
xrange
(
F
.
shape
[
1
]):
for
x
in
xrange
(
F
.
shape
[
1
]):
g
=
G
[
x
,
y
]
g
=
G
[
y
,
x
]
a
=
A
[
x
,
y
]
a
=
A
[
y
,
x
]
compare
=
[((
x
,
y
-
1
),
(
x
,
y
+
1
)),
((
x
-
1
,
y
-
1
),
\
compare
=
[((
y
,
x
-
1
),
(
y
,
x
+
1
)),
((
y
-
1
,
x
-
1
),
\
(
x
+
1
,
y
+
1
)),
((
x
-
1
,
y
),
(
x
+
1
,
y
)),
\
(
y
+
1
,
x
+
1
)),
((
y
-
1
,
x
),
(
y
+
1
,
x
)),
\
((
x
+
1
,
y
-
1
),
(
x
-
1
,
y
+
1
))]
((
y
+
1
,
x
-
1
),
(
y
-
1
,
x
+
1
))]
na
,
nb
=
compare
[
a
]
na
,
nb
=
compare
[
a
]
if
(
not
in_image
(
na
,
G
)
or
g
>
G
[
na
])
\
if
(
not
in_image
(
na
,
G
)
or
g
>
G
[
na
])
\
and
(
not
in_image
(
nb
,
G
)
or
g
>
G
[
nb
]):
and
(
not
in_image
(
nb
,
G
)
or
g
>
G
[
nb
]):
E
[
x
,
y
]
=
g
E
[
y
,
x
]
=
g
# Only execute hysteresis thresholding if the thresholds are specified
# Only execute hysteresis thresholding if the thresholds are specified
if
Tl
is
None
or
Th
is
None
:
if
Tl
is
None
or
Th
is
None
:
...
@@ -57,29 +57,29 @@ def canny(F, s, Tl=None, Th=None):
...
@@ -57,29 +57,29 @@ def canny(F, s, Tl=None, Th=None):
T
=
zeros
(
F
.
shape
,
dtype
=
bool
)
T
=
zeros
(
F
.
shape
,
dtype
=
bool
)
# Clear image borders
# Clear image borders
for
x
in
xrange
(
F
.
shape
[
0
]):
for
y
in
xrange
(
F
.
shape
[
0
]):
E
[
x
,
0
]
=
E
[
x
,
F
.
shape
[
1
]
-
1
]
=
0
E
[
x
,
0
]
=
E
[
y
,
F
.
shape
[
1
]
-
1
]
=
0
for
y
in
xrange
(
1
,
F
.
shape
[
1
]
-
1
):
for
x
in
xrange
(
x
,
F
.
shape
[
1
]
-
1
):
E
[
0
,
y
]
=
E
[
F
.
shape
[
0
]
-
1
,
y
]
=
0
E
[
0
,
x
]
=
E
[
F
.
shape
[
0
]
-
1
,
x
]
=
0
def
follow_nb
(
x
,
y
):
def
follow_nb
(
y
,
x
):
"""Follow the neighbouring pixels of an edge pixel in E recursively."""
"""Follow the neighbouring pixels of an edge pixel in E recursively."""
if
T
[
x
,
y
]:
if
T
[
y
,
x
]:
return
return
T
[
x
,
y
]
=
True
T
[
y
,
x
]
=
True
for
n
x
in
xrange
(
-
1
,
2
):
for
n
y
in
xrange
(
-
1
,
2
):
for
n
y
in
xrange
(
-
1
,
2
):
for
n
x
in
xrange
(
-
1
,
2
):
if
(
n
x
!=
0
or
ny
!=
0
)
and
E
[
nx
,
ny
]
>
Tl
:
if
(
n
y
or
nx
)
and
E
[
ny
,
nx
]
>
Tl
:
follow_nb
(
n
x
,
ny
)
follow_nb
(
n
y
,
nx
)
# Follow edges that have a starting value above Th
# Follow edges that have a starting value above Th
for
x
in
xrange
(
F
.
shape
[
0
]):
for
y
in
xrange
(
F
.
shape
[
0
]):
for
y
in
xrange
(
F
.
shape
[
1
]):
for
x
in
xrange
(
F
.
shape
[
1
]):
if
E
[
x
,
y
]
>
Th
:
if
E
[
y
,
x
]
>
Th
:
follow_nb
(
x
,
y
)
follow_nb
(
y
,
x
)
return
E
,
T
return
E
,
T
...
...
improc/ass4/gauss.py
View file @
7cb2a9ff
...
@@ -31,12 +31,17 @@ def Gauss(s):
...
@@ -31,12 +31,17 @@ def Gauss(s):
return
W
/
W
.
sum
()
return
W
/
W
.
sum
()
def
f_gauss
(
x
,
s
):
def
f_gauss
(
x
,
s
):
"""Return the Gaussian function for a given x and scale."""
return
exp
(
-
(
x
**
2
/
(
2
*
s
**
2
)))
/
(
sqrt
(
2
*
pi
)
*
s
)
return
exp
(
-
(
x
**
2
/
(
2
*
s
**
2
)))
/
(
sqrt
(
2
*
pi
)
*
s
)
def
f_gauss_der_1
(
x
,
s
):
def
f_gauss_der_1
(
x
,
s
):
"""Return the first derivative of the Gaussian function for a given x
and scale."""
return
-
x
*
exp
(
-
(
x
**
2
/
(
2
*
s
**
2
)))
/
(
sqrt
(
2
*
pi
)
*
s
**
3
)
return
-
x
*
exp
(
-
(
x
**
2
/
(
2
*
s
**
2
)))
/
(
sqrt
(
2
*
pi
)
*
s
**
3
)
def
f_gauss_der_2
(
x
,
s
):
def
f_gauss_der_2
(
x
,
s
):
"""Return the second derivative of the Gaussian function for a given x
and scale."""
return
(
x
**
2
-
s
**
2
)
*
exp
(
-
(
x
**
2
/
(
2
*
s
**
2
)))
\
return
(
x
**
2
-
s
**
2
)
*
exp
(
-
(
x
**
2
/
(
2
*
s
**
2
)))
\
/
(
sqrt
(
2
*
pi
)
*
s
**
5
)
/
(
sqrt
(
2
*
pi
)
*
s
**
5
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment