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
73c83038
Commit
73c83038
authored
Oct 11, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improc ass4: Added 1d Gaussian function to timer option.
parent
0c734114
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
55 deletions
+90
-55
improc/ass4/gauss.py
improc/ass4/gauss.py
+90
-55
improc/ass4/report/gauss_times_1d.pdf
improc/ass4/report/gauss_times_1d.pdf
+0
-0
improc/ass4/report/gauss_times_2d.pdf
improc/ass4/report/gauss_times_2d.pdf
+0
-0
No files found.
improc/ass4/gauss.py
View file @
73c83038
#!/usr/bin/env python
#!/usr/bin/env python
from
numpy
import
zeros
,
arange
,
pi
,
e
,
ceil
,
meshgrid
from
numpy
import
zeros
,
arange
,
pi
,
e
,
ceil
,
meshgrid
,
array
from
matplotlib.pyplot
import
imread
,
imshow
,
plot
,
xlabel
,
ylabel
,
show
,
\
from
matplotlib.pyplot
import
imread
,
imshow
,
plot
,
xlabel
,
ylabel
,
show
,
\
subplot
,
xlim
,
savefig
subplot
,
xlim
,
savefig
from
mpl_toolkits.mplot3d
import
Axes3D
from
mpl_toolkits.mplot3d
import
Axes3D
from
scipy.ndimage
import
convolve
from
scipy.ndimage
import
convolve
,
convolve1d
from
time
import
time
from
time
import
time
from
sys
import
argv
,
exit
from
sys
import
argv
,
exit
def
exit_with_usage
():
def
exit_with_usage
():
"""Print an error message with the program's usage and exit the program."""
"""Print an error message with the program's usage and exit the program."""
print
'Usage: python %s timer
REPEAT
| diff SCALE'
%
argv
[
0
]
print
'Usage: python %s timer
METHOD [ REPEAT ]
| diff SCALE'
%
argv
[
0
]
exit
(
1
)
exit
(
1
)
def
Gauss
(
s
):
def
Gauss
(
s
):
"""
Create a sampled
Gaussian function of scale s."""
"""
Sample a two-dimensional
Gaussian function of scale s."""
size
=
int
(
ceil
(
3
*
s
))
size
=
int
(
ceil
(
3
*
s
))
r
=
2
*
size
+
1
r
=
2
*
size
W
=
zeros
((
r
,
r
))
W
=
zeros
((
r
,
r
))
t
=
s
**
2.
t
=
float
(
s
)
**
2
a
=
1
/
(
2
*
pi
*
t
)
a
=
1
/
(
2
*
pi
*
t
)
# Sample the Gaussian function
# Sample the Gaussian function
...
@@ -28,57 +28,92 @@ def Gauss(s):
...
@@ -28,57 +28,92 @@ def Gauss(s):
# Make sure that the sum of all kernel values is equal to one
# Make sure that the sum of all kernel values is equal to one
return
W
/
W
.
sum
()
return
W
/
W
.
sum
()
if
len
(
argv
)
<
2
:
def
Gauss1
(
s
):
exit_with_usage
()
"""Sample a one-dimensional Gaussian function of scale s."""
size
=
int
(
ceil
(
3
*
s
))
F
=
imread
(
'cameraman.png'
)
r
=
2
*
size
W
=
zeros
((
r
,))
if
argv
[
1
]
==
'timer'
:
t
=
float
(
s
)
**
2
# Time for multiple scales
a
=
1
/
(
2
*
pi
*
t
)
S
=
[
1
,
2
,
3
,
5
,
7
,
9
,
11
,
15
,
19
]
repeat
=
int
(
argv
[
2
])
timings
=
[]
for
i
,
s
in
enumerate
(
S
):
t
=
0
for
k
in
xrange
(
repeat
):
# Sample the Gaussian function
W
=
Gauss
(
s
)
W
=
array
([
a
*
e
**
-
((
x
-
size
)
**
2
/
(
2
*
t
))
for
x
in
xrange
(
r
)])
start
=
time
()
convolve
(
F
,
W
,
mode
=
'nearest'
)
t
+=
time
()
-
start
timings
.
append
(
t
/
repeat
)
# Make sure that the sum of all kernel values is equal to one
return
W
/
W
.
sum
()
xlim
(
S
[
0
],
S
[
-
1
])
if
__name__
==
'__main__'
:
xlabel
(
's'
)
if
len
(
argv
)
<
2
:
ylabel
(
'time (s)'
)
plot
(
S
,
timings
,
'o-'
)
elif
argv
[
1
]
==
'diff'
:
# Calculate and plot the convolution of the given scale
if
len
(
argv
)
<
3
:
exit_with_usage
()
exit_with_usage
()
s
=
float
(
argv
[
2
])
F
=
imread
(
'cameraman.png'
)
W
=
Gauss
(
s
)
G
=
convolve
(
F
,
W
,
mode
=
'nearest'
)
#W1 = Gauss1(10)
#X = arange(W1.shape[0])
# Original image
#G = convolve1d(F, W1, axis=0, mode='nearest')
subplot
(
131
)
#subplot(121)
imshow
(
F
,
cmap
=
'gray'
)
#imshow(F, cmap='gray')
#subplot(122)
# Gauss function (3D plot)
#imshow(G, cmap='gray')
x
=
arange
(
W
.
shape
[
0
])
#show()
X
,
Y
=
meshgrid
(
x
,
x
)
#exit(0)
ax
=
subplot
(
132
,
projection
=
'3d'
)
stride
=
s
/
4
if
argv
[
1
]
==
'timer'
:
ax
.
plot_surface
(
X
,
Y
,
W
,
rstride
=
stride
,
cstride
=
stride
,
cmap
=
'jet'
)
if
len
(
argv
)
<
3
:
ax
.
set_xlabel
(
'x'
)
exit_with_usage
()
ax
.
set_ylabel
(
'y'
)
ax
.
set_zlabel
(
'g(x, y)'
)
method
=
argv
[
2
]
# Convolution
# Time for multiple scales
subplot
(
133
)
S
=
[
1
,
2
,
3
,
5
,
7
,
9
,
11
,
15
,
19
]
imshow
(
G
,
cmap
=
'gray'
)
repeat
=
int
(
argv
[
3
])
if
len
(
argv
)
>
3
else
1
n
=
0
show
()
times
=
[]
for
i
,
s
in
enumerate
(
S
):
t
=
0
for
k
in
xrange
(
repeat
):
start
=
time
()
if
method
==
'1d'
:
convolve1d
(
F
,
Gauss1
(
s
),
axis
=
n
,
mode
=
'nearest'
)
elif
method
==
'2d'
:
convolve
(
F
,
Gauss
(
s
),
mode
=
'nearest'
)
t
+=
time
()
-
start
times
.
append
(
t
/
repeat
)
xlim
(
S
[
0
],
S
[
-
1
])
xlabel
(
's'
)
ylabel
(
'time (s)'
)
plot
(
S
,
times
,
'o-'
)
elif
argv
[
1
]
==
'diff'
:
# Calculate and plot the convolution of the given scale
if
len
(
argv
)
<
3
:
exit_with_usage
()
s
=
float
(
argv
[
2
])
W
=
Gauss
(
s
)
G
=
convolve
(
F
,
W
,
mode
=
'nearest'
)
# Original image
subplot
(
131
)
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)'
)
# Convolution
subplot
(
133
)
imshow
(
G
,
cmap
=
'gray'
)
show
()
improc/ass4/report/gauss_times_1d.pdf
0 → 100644
View file @
73c83038
File added
improc/ass4/report/gauss_times_2d.pdf
0 → 100644
View file @
73c83038
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