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
af846a58
Commit
af846a58
authored
Sep 09, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ImProc ass1: Finished assignment 1 code.
parent
2bb870d9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
0 deletions
+103
-0
improc/ass1/cameraman.png
improc/ass1/cameraman.png
+0
-0
improc/ass1/linfilters.py
improc/ass1/linfilters.py
+62
-0
improc/ass1/timer.py
improc/ass1/timer.py
+41
-0
No files found.
improc/ass1/cameraman.png
0 → 100644
View file @
af846a58
51.2 KB
improc/ass1/linfilters.py
0 → 100644
View file @
af846a58
from
numpy
import
*
def
linfilter1
(
f
,
w
):
g
=
empty
(
f
.
shape
,
dtype
=
f
.
dtype
)
M
,
N
=
f
.
shape
K
,
L
=
(
array
(
w
.
shape
)
-
1
)
/
2
def
value
(
i
,
j
):
"""The function returning the value f[i,j] in case
(i,j) in an index 'in the image', otherwise it return 0"""
if
i
<
0
or
i
>=
M
or
j
<
0
or
j
>=
N
:
return
0
return
f
[
i
,
j
]
for
j
in
xrange
(
N
):
for
i
in
xrange
(
M
):
summed
=
0
for
k
in
xrange
(
-
K
,
K
+
1
):
for
l
in
xrange
(
-
L
,
L
+
1
):
summed
+=
value
(
i
+
k
,
j
+
l
)
*
w
[
k
+
K
,
l
+
L
]
g
[
i
,
j
]
=
summed
return
g
def
linfilter2
(
f
,
w
):
"""Linear Correlation based on neigborhood processing without loops"""
g
=
empty
(
f
.
shape
,
dtype
=
f
.
dtype
)
M
,
N
=
f
.
shape
K
,
L
=
(
array
(
w
.
shape
)
-
1
)
/
2
for
j
in
xrange
(
N
):
for
i
in
xrange
(
M
):
ii
=
minimum
(
M
-
1
,
maximum
(
0
,
arange
(
i
-
K
,
i
+
K
+
1
)))
jj
=
minimum
(
N
-
1
,
maximum
(
0
,
arange
(
j
-
L
,
j
+
L
+
1
)))
nbh
=
f
[
ix_
(
ii
,
jj
)]
g
[
i
,
j
]
=
(
nbh
*
w
).
sum
()
return
g
def
linfilter3
(
f
,
w
):
"""Linear Correlation using Translates of Images"""
M
,
N
=
f
.
shape
K
,
L
=
(
array
(
w
.
shape
)
-
1
)
/
2
di
,
dj
=
meshgrid
(
arange
(
-
L
,
L
+
1
),
arange
(
-
K
,
K
+
1
))
didjw
=
zip
(
di
.
flatten
(),
dj
.
flatten
(),
w
.
flatten
())
def
translate
(
di
,
dj
):
ii
=
minimum
(
M
-
1
,
maximum
(
0
,
di
+
arange
(
M
)))
jj
=
minimum
(
N
-
1
,
maximum
(
0
,
dj
+
arange
(
N
)))
return
f
[
ix_
(
ii
,
jj
)]
r
=
0
*
f
for
di
,
dj
,
weight
in
didjw
:
r
+=
weight
*
translate
(
di
,
dj
)
return
r
def
linfilter4
(
f
,
w
):
return
correlate
(
f
,
w
,
mode
=
'nearest'
)
improc/ass1/timer.py
0 → 100644
View file @
af846a58
from
linfilters
import
*
from
scipy.ndimage.interpolation
import
zoom
from
pylab
import
*
from
time
import
time
repeat
=
1
w
=
(
3
,
11
)
f
=
zoom
(
imread
(
'cameraman.png'
),
.
25
)
methods
=
[
linfilter1
,
linfilter2
,
linfilter3
]
#, linfilter4]
timings
=
[[]
for
i
in
methods
]
x
=
range
(
w
[
0
],
w
[
1
]
+
1
,
2
)
for
i
,
method
in
enumerate
(
methods
):
for
j
in
x
:
weight
=
ones
((
j
,
j
))
/
(
j
**
2
)
t
=
0
for
k
in
xrange
(
repeat
):
start
=
time
()
method
(
f
,
weight
)
t
+=
time
()
-
start
timings
[
i
].
append
(
t
/
repeat
)
for
times
in
timings
:
plot
(
x
,
times
,
'o-'
)
semilogy
()
show
()
#subplot(1, 3, 1)
#imshow(a)
#f = zoom(a, .25)
#g = linfilter1(f, ones((5, 5)) / 25)
#subplot(1, 3, 2)
#imshow(f)
#subplot(1, 3, 3)
#imshow(g)
#show()
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