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
03165c7d
Commit
03165c7d
authored
Nov 04, 2011
by
Taddes Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improc ass4: Fixed angles bug in Canny and added subplot titles.
parent
94f437b9
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
23 deletions
+32
-23
improc/ass4/canny.py
improc/ass4/canny.py
+17
-12
improc/ass4/gauss.py
improc/ass4/gauss.py
+11
-7
improc/ass4/report/canny_2_20_60.pdf
improc/ass4/report/canny_2_20_60.pdf
+0
-0
improc/ass4/report/canny_2_50_70.pdf
improc/ass4/report/canny_2_50_70.pdf
+0
-0
improc/ass4/report/gauss_1d_5_2_2.pdf
improc/ass4/report/gauss_1d_5_2_2.pdf
+0
-0
improc/ass4/report/gauss_2d_5.pdf
improc/ass4/report/gauss_2d_5.pdf
+0
-0
improc/ass4/report/report.tex
improc/ass4/report/report.tex
+4
-4
No files found.
improc/ass4/canny.py
View file @
03165c7d
#!/usr/bin/env python
#!/usr/bin/env python
from
matplotlib.pyplot
import
imread
,
imshow
,
subplot
,
show
from
matplotlib.pyplot
import
imread
,
imshow
,
subplot
,
show
,
axis
from
numpy
import
arctan2
,
zeros
,
append
,
pi
from
numpy
import
arctan2
,
zeros
,
append
,
pi
from
numpy.linalg
import
norm
from
numpy.linalg
import
norm
from
scipy.ndimage
import
convolve1d
from
scipy.ndimage
import
convolve1d
...
@@ -29,19 +29,19 @@ def canny(F, s, Tl=None, Th=None):
...
@@ -29,19 +29,19 @@ def canny(F, s, Tl=None, Th=None):
# Gradient norm and rounded angle
# Gradient norm and rounded angle
G
[
p
]
=
norm
(
append
(
Gy
[
p
],
Gx
[
p
]))
G
[
p
]
=
norm
(
append
(
Gy
[
p
],
Gx
[
p
]))
A
[
p
]
=
int
(
round
(
arctan2
(
Gy
[
p
],
Gx
[
p
])
*
4
/
pi
+
1
))
%
4
A
[
p
]
=
(
4
-
int
(
round
(
4
*
arctan2
(
Gy
[
p
],
Gx
[
p
])
/
pi
)
))
%
4
# Non-maximum suppression
# Non-maximum suppression
E
=
zeros
(
F
.
shape
)
E
=
zeros
(
F
.
shape
)
compare
=
[((
-
1
,
0
),
(
1
,
0
)),
((
-
1
,
1
),
(
1
,
-
1
)),
\
((
0
,
1
),
(
0
,
-
1
)),
((
1
,
1
),
(
-
1
,
-
1
))]
for
y
in
xrange
(
F
.
shape
[
0
]):
for
y
in
xrange
(
F
.
shape
[
0
]):
for
x
in
xrange
(
F
.
shape
[
1
]):
for
x
in
xrange
(
F
.
shape
[
1
]):
g
=
G
[
y
,
x
]
g
=
G
[
y
,
x
]
a
=
A
[
y
,
x
]
a
,
b
=
compare
[
A
[
y
,
x
]]
compare
=
[((
y
,
x
-
1
),
(
y
,
x
+
1
)),
((
y
-
1
,
x
-
1
),
\
na
=
(
y
+
a
[
1
],
x
+
a
[
0
])
(
y
+
1
,
x
+
1
)),
((
y
-
1
,
x
),
(
y
+
1
,
x
)),
\
nb
=
(
y
+
b
[
1
],
x
+
b
[
0
])
((
y
+
1
,
x
-
1
),
(
y
-
1
,
x
+
1
))]
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
]):
...
@@ -101,19 +101,24 @@ if __name__ == '__main__':
...
@@ -101,19 +101,24 @@ if __name__ == '__main__':
# Execute with tracing edges
# Execute with tracing edges
E
,
T
=
canny
(
F
,
s
,
float
(
argv
[
2
]),
float
(
argv
[
3
]))
E
,
T
=
canny
(
F
,
s
,
float
(
argv
[
2
]),
float
(
argv
[
3
]))
subplot
(
131
)
subplot
(
131
,
title
=
'Original image'
)
imshow
(
F
,
cmap
=
'gray'
)
imshow
(
F
,
cmap
=
'gray'
)
subplot
(
132
)
axis
(
'off'
)
subplot
(
132
,
title
=
'Gradient magnitudes'
)
imshow
(
E
,
cmap
=
'gray'
)
imshow
(
E
,
cmap
=
'gray'
)
subplot
(
133
)
axis
(
'off'
)
subplot
(
133
,
title
=
'Thresholds applied'
)
imshow
(
T
,
cmap
=
'gray'
)
imshow
(
T
,
cmap
=
'gray'
)
axis
(
'off'
)
else
:
else
:
# Execute until nn-maximum suppression
# Execute until nn-maximum suppression
E
=
canny
(
F
,
s
)
E
=
canny
(
F
,
s
)
subplot
(
121
)
subplot
(
121
,
title
=
'Original image'
)
imshow
(
F
,
cmap
=
'gray'
)
imshow
(
F
,
cmap
=
'gray'
)
subplot
(
122
)
axis
(
'off'
)
subplot
(
122
,
title
=
'Gradient magnitudes'
)
imshow
(
E
,
cmap
=
'gray'
)
imshow
(
E
,
cmap
=
'gray'
)
axis
(
'off'
)
show
()
show
()
improc/ass4/gauss.py
View file @
03165c7d
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
from
numpy
import
zeros
,
arange
,
meshgrid
,
array
,
matrix
from
numpy
import
zeros
,
arange
,
meshgrid
,
array
,
matrix
from
math
import
ceil
,
exp
,
pi
,
sqrt
from
math
import
ceil
,
exp
,
pi
,
sqrt
from
matplotlib.pyplot
import
imread
,
imshow
,
plot
,
xlabel
,
ylabel
,
show
,
\
from
matplotlib.pyplot
import
imread
,
imshow
,
plot
,
xlabel
,
ylabel
,
show
,
\
subplot
,
xlim
,
savefig
,
axis
subplot
,
xlim
,
savefig
,
axis
,
ticklabel_format
from
mpl_toolkits.mplot3d
import
Axes3D
from
mpl_toolkits.mplot3d
import
Axes3D
from
scipy.ndimage
import
convolve
,
convolve1d
from
scipy.ndimage
import
convolve
,
convolve1d
from
time
import
time
from
time
import
time
...
@@ -96,11 +96,13 @@ if __name__ == '__main__':
...
@@ -96,11 +96,13 @@ if __name__ == '__main__':
G
=
convolve
(
F
,
W
,
mode
=
'nearest'
)
G
=
convolve
(
F
,
W
,
mode
=
'nearest'
)
# Show the original image, kernel and convoluted image respectively
# Show the original image, kernel and convoluted image respectively
subplot
(
131
)
subplot
(
131
,
title
=
'Original image'
)
imshow
(
F
,
cmap
=
'gray'
)
imshow
(
F
,
cmap
=
'gray'
)
plot_kernel
(
W
,
subplot
(
132
,
projection
=
'3d'
))
axis
(
'off'
)
subplot
(
133
)
plot_kernel
(
W
,
subplot
(
132
,
projection
=
'3d'
,
title
=
'Kernel'
))
subplot
(
133
,
title
=
'Convoluted image'
)
imshow
(
G
,
cmap
=
'gray'
)
imshow
(
G
,
cmap
=
'gray'
)
axis
(
'off'
)
elif
argv
[
1
]
==
'1d'
:
elif
argv
[
1
]
==
'1d'
:
"""Calculate the gaussian kernel using derivatives of the specified
"""Calculate the gaussian kernel using derivatives of the specified
order in both directions."""
order in both directions."""
...
@@ -119,11 +121,13 @@ if __name__ == '__main__':
...
@@ -119,11 +121,13 @@ if __name__ == '__main__':
W
=
Fy
.
T
*
Fx
W
=
Fy
.
T
*
Fx
# Show the original image, kernel and convoluted image respectively
# Show the original image, kernel and convoluted image respectively
subplot
(
131
)
subplot
(
131
,
title
=
'Original image'
)
imshow
(
F
,
cmap
=
'gray'
)
imshow
(
F
,
cmap
=
'gray'
)
plot_kernel
(
W
,
subplot
(
132
,
projection
=
'3d'
))
axis
(
'off'
)
subplot
(
133
)
plot_kernel
(
W
,
subplot
(
132
,
projection
=
'3d'
,
title
=
'Kernel'
))
subplot
(
133
,
title
=
'Convoluted image'
)
imshow
(
G
,
cmap
=
'gray'
)
imshow
(
G
,
cmap
=
'gray'
)
axis
(
'off'
)
elif
argv
[
1
]
==
'timer'
:
elif
argv
[
1
]
==
'timer'
:
"""Time the performance of a 1D/2D convolution and plot the results."""
"""Time the performance of a 1D/2D convolution and plot the results."""
if
len
(
argv
)
<
3
:
if
len
(
argv
)
<
3
:
...
...
improc/ass4/report/canny_2_20_60.pdf
deleted
100644 → 0
View file @
94f437b9
File deleted
improc/ass4/report/canny_2_50_70.pdf
0 → 100644
View file @
03165c7d
File added
improc/ass4/report/gauss_1d_5_2_2.pdf
deleted
100644 → 0
View file @
94f437b9
File deleted
improc/ass4/report/gauss_2d_5.pdf
View file @
03165c7d
No preview for this file type
improc/ass4/report/report.tex
View file @
03165c7d
...
@@ -88,7 +88,7 @@ The result of the \texttt{Gauss} function is shown in figure
...
@@ -88,7 +88,7 @@ The result of the \texttt{Gauss} function is shown in figure
Gaussian kernel and the convolved image.
Gaussian kernel and the convolved image.
\begin{figure}
[H]
\begin{figure}
[H]
\hspace
{
-
5
cm
}
\hspace
{
-
3
cm
}
\includegraphics
[scale=.6]
{
gauss
_
2d
_
5.pdf
}
\includegraphics
[scale=.6]
{
gauss
_
2d
_
5.pdf
}
\caption
{
The result of
\texttt
{
python gauss.py 2d 5
}
.
}
\caption
{
The result of
\texttt
{
python gauss.py 2d 5
}
.
}
\label
{
fig:gauss-2d
}
\label
{
fig:gauss-2d
}
...
@@ -202,12 +202,12 @@ the resulting plot will contain an additional image containing a binary image
...
@@ -202,12 +202,12 @@ the resulting plot will contain an additional image containing a binary image
of edges. The thresholds can be specified in the range 0-255, they are scaled
of edges. The thresholds can be specified in the range 0-255, they are scaled
down by the program to match the image's color range. An example execution of
down by the program to match the image's color range. An example execution of
edge detection on the cameraman image using a scale of 2, a lower threshold of
edge detection on the cameraman image using a scale of 2, a lower threshold of
20 and a higher threshold of 6
0, can be viewed in figure
\ref
{
fig:canny
}
.
50 and a higher threshold of 7
0, can be viewed in figure
\ref
{
fig:canny
}
.
\begin{figure}
[H]
\begin{figure}
[H]
\hspace
{
-5cm
}
\hspace
{
-5cm
}
\includegraphics
[scale=.6]
{
canny
_
2
_
20
_
6
0.pdf
}
\includegraphics
[scale=.6]
{
canny
_
2
_
50
_
7
0.pdf
}
\caption
{
The result of
\texttt
{
python canny.py 2
20 6
0
}
.
}
\caption
{
The result of
\texttt
{
python canny.py 2
50 7
0
}
.
}
\label
{
fig:canny
}
\label
{
fig:canny
}
\end{figure}
\end{figure}
...
...
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