Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uva
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
uva
Commits
af846a58
Commit
af846a58
authored
13 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
ImProc ass1: Finished assignment 1 code.
parent
2bb870d9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
improc/ass1/cameraman.png
+0
-0
0 additions, 0 deletions
improc/ass1/cameraman.png
improc/ass1/linfilters.py
+62
-0
62 additions, 0 deletions
improc/ass1/linfilters.py
improc/ass1/timer.py
+41
-0
41 additions, 0 deletions
improc/ass1/timer.py
with
103 additions
and
0 deletions
improc/ass1/cameraman.png
0 → 100644
+
0
−
0
View file @
af846a58
51.2 KiB
This diff is collapsed.
Click to expand it.
improc/ass1/linfilters.py
0 → 100644
+
62
−
0
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
'
)
This diff is collapsed.
Click to expand it.
improc/ass1/timer.py
0 → 100644
+
41
−
0
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()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment