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
97a4fa53
Commit
97a4fa53
authored
Oct 12, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improc ass4: Added Gaussian derivative functions.
parent
73c83038
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
23 deletions
+46
-23
improc/ass4/gauss.py
improc/ass4/gauss.py
+46
-23
improc/ass4/report/gauss_der_5_2_2.pdf
improc/ass4/report/gauss_der_5_2_2.pdf
+0
-0
No files found.
improc/ass4/gauss.py
View file @
97a4fa53
...
...
@@ -9,7 +9,8 @@ from sys import argv, exit
def
exit_with_usage
():
"""Print an error message with the program's usage and exit the program."""
print
'Usage: python %s timer METHOD [ REPEAT ] | diff SCALE'
%
argv
[
0
]
print
'Usage: python %s timer METHOD [ REPEAT ] | diff SCALE'
\
' | der SCALE IORDER JORDER'
%
argv
[
0
]
exit
(
1
)
def
Gauss
(
s
):
...
...
@@ -42,32 +43,61 @@ def Gauss1(s):
# Make sure that the sum of all kernel values is equal to one
return
W
/
W
.
sum
()
def
plot_mask
(
W
,
ax
,
stride
):
""""""
x
=
arange
(
W
.
shape
[
0
])
Y
,
X
=
meshgrid
(
x
,
x
)
ax
.
plot_surface
(
X
,
Y
,
W
,
rstride
=
stride
,
cstride
=
stride
,
cmap
=
'jet'
)
ax
.
set_xlabel
(
'x'
)
ax
.
set_ylabel
(
'y'
)
ax
.
set_zlabel
(
'g(x, y)'
)
def
gD
(
F
,
s
,
iorder
,
jorder
):
"""Create the Gaussian derivative convolution of image F."""
funcs
=
[
lambda
x
:
e
**
-
(
x
**
2
/
(
2
*
s
**
2
))
/
(
2
*
pi
*
s
**
2
),
\
lambda
x
:
-
x
*
e
**
-
(
x
**
2
/
(
2
*
s
**
2
))
\
/
(
2
*
pi
*
s
**
4
),
\
lambda
x
:
-
(
x
**
2
-
s
**
2
)
*
e
**
-
(
x
**
2
/
(
2
*
s
**
2
))
\
/
(
2
*
pi
*
s
**
6
)]
size
=
int
(
ceil
(
3
*
s
))
r
=
2
*
size
iterator
=
map
(
float
,
range
(
r
))
W
=
zeros
((
r
,
r
))
Fx
=
funcs
[
iorder
]
Fy
=
funcs
[
jorder
]
for
x
in
iterator
:
for
y
in
iterator
:
W
[
x
,
y
]
=
Fx
(
x
-
size
)
*
Fy
(
y
-
size
)
return
W
,
convolve
(
F
,
W
,
mode
=
'nearest'
)
if
__name__
==
'__main__'
:
if
len
(
argv
)
<
2
:
exit_with_usage
()
F
=
imread
(
'cameraman.png'
)
#W1 = Gauss1(10)
#X = arange(W1.shape[0])
#G = convolve1d(F, W1, axis=0, mode='nearest')
#subplot(121)
#imshow(F, cmap='gray')
#subplot(122)
#imshow(G, cmap='gray')
#show()
#exit(0)
if
argv
[
1
]
==
'timer'
:
if
argv
[
1
]
==
'der'
:
if
len
(
argv
)
<
5
:
exit_with_usage
()
s
=
float
(
argv
[
2
])
W
,
G
=
gD
(
F
,
s
,
int
(
argv
[
3
]),
int
(
argv
[
4
]))
subplot
(
131
)
imshow
(
F
,
cmap
=
'gray'
)
plot_mask
(
W
,
subplot
(
132
,
projection
=
'3d'
),
s
/
4
)
subplot
(
133
)
imshow
(
G
,
cmap
=
'gray'
)
elif
argv
[
1
]
==
'timer'
:
if
len
(
argv
)
<
3
:
exit_with_usage
()
method
=
argv
[
2
]
repeat
=
int
(
argv
[
3
])
if
len
(
argv
)
>
3
else
1
# Time for multiple scales
S
=
[
1
,
2
,
3
,
5
,
7
,
9
,
11
,
15
,
19
]
repeat
=
int
(
argv
[
3
])
if
len
(
argv
)
>
3
else
1
n
=
0
times
=
[]
for
i
,
s
in
enumerate
(
S
):
...
...
@@ -77,7 +107,7 @@ if __name__ == '__main__':
start
=
time
()
if
method
==
'1d'
:
convolve1d
(
F
,
Gauss1
(
s
),
axis
=
n
,
mode
=
'nearest'
)
convolve1d
(
F
,
Gauss1
(
s
),
axis
=
0
,
mode
=
'nearest'
)
elif
method
==
'2d'
:
convolve
(
F
,
Gauss
(
s
),
mode
=
'nearest'
)
...
...
@@ -103,14 +133,7 @@ if __name__ == '__main__':
imshow
(
F
,
cmap
=
'gray'
)
# Gauss function (3D plot)
x
=
arange
(
W
.
shape
[
0
])
Y
,
X
=
meshgrid
(
x
,
x
)
ax
=
subplot
(
132
,
projection
=
'3d'
)
stride
=
s
/
4
ax
.
plot_surface
(
X
,
Y
,
W
,
rstride
=
stride
,
cstride
=
stride
,
cmap
=
'jet'
)
ax
.
set_xlabel
(
'x'
)
ax
.
set_ylabel
(
'y'
)
ax
.
set_zlabel
(
'g(x, y)'
)
plot_mask
(
W
,
subplot
(
132
,
projection
=
'3d'
),
s
/
4
)
# Convolution
subplot
(
133
)
...
...
improc/ass4/report/gauss_der_5_2_2.pdf
0 → 100644
View file @
97a4fa53
File added
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