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
401a095d
Commit
401a095d
authored
Sep 22, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improc: WIP on ass2.
parent
1a0c8b6c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
11 deletions
+79
-11
improc/ass2/affine.py
improc/ass2/affine.py
+66
-0
improc/ass2/interpolation.py
improc/ass2/interpolation.py
+5
-5
modsim/ass4_sander/part2/main.c
modsim/ass4_sander/part2/main.c
+8
-6
No files found.
improc/ass2/affine.py
0 → 100644
View file @
401a095d
from
interpolation
import
in_image
,
pv
from
numpy
import
array
,
zeros
from
numpy.linalg
import
lstsq
# url: http://www.leptonica.com/affine.html
def
affine_transform
(
image
,
p1
,
p2
,
p3
,
width
,
height
):
"""Warps the parallelogram defined by the three points (x1,y1), (x2,y2) and
(x3,y3) onto a new image of size MxN."""
x1
,
y1
=
p1
x2
,
y2
=
p2
x3
,
y3
=
p3
M
=
array
([[
x1
,
y1
,
1
,
0
,
0
,
0
],
[
0
,
0
,
0
,
x1
,
y1
,
1
],
[
x2
,
y2
,
1
,
0
,
0
,
0
],
[
0
,
0
,
0
,
x2
,
y2
,
1
],
[
x3
,
y3
,
1
,
0
,
0
,
0
],
[
0
,
0
,
0
,
x3
,
y3
,
1
]])
q
=
array
([[
x1
],
[
y1
],
[
x2
],
[
y2
],
[
x3
],
[
y3
]])
# Calculate transform matrix
p
=
lstsq
(
M
,
q
)[
0
]
T
=
p
.
reshape
(
2
,
3
).
T
# Construct the transformed image
result
=
zeros
((
width
,
height
))
for
y
in
xrange
(
height
):
for
x
in
xrange
(
width
):
# TODO: multiplication using '*' or 'dot()' ?
# XXX: where is |0 0 1| in T, since p.reshape(2, 3) ?
# |x'| |a b c| |x|
# |y'| = |d e f| |y|
# |1 | |0 0 1| |1|
orig_pos
=
array
([
x
,
y
,
1
]).
reshape
(
3
,
1
)
*
T
#print x,y, tmp
#result[y][x] =
return
result
if
__name__
==
'__main__'
:
from
pylab
import
imread
,
imshow
image
=
imread
(
'cameraman.png'
)
half_width
=
image
.
shape
[
0
]
/
2
half_height
=
image
.
shape
[
1
]
/
2
M
,
N
=
image
.
shape
# TODO: validate MxN -> width x height
result
=
affine_transform
(
image
,
(
0.
,
0.
),
(
0.
,
half_height
),
(
half_width
,
half_height
),
M
,
N
)
imshow
(
result
)
improc/ass2/interpolation.py
View file @
401a095d
...
@@ -2,11 +2,11 @@ from math import floor, ceil
...
@@ -2,11 +2,11 @@ from math import floor, ceil
bgcolor
=
0
bgcolor
=
0
def
in
I
mage
(
image
,
x
,
y
):
def
in
_i
mage
(
image
,
x
,
y
):
return
x
>=
0
and
y
>=
0
and
x
<
image
.
shape
[
0
]
and
y
<
image
.
shape
[
1
]
return
x
>=
0
and
y
>=
0
and
x
<
image
.
shape
[
0
]
and
y
<
image
.
shape
[
1
]
def
p
V
(
image
,
x
,
y
,
method
):
def
p
v
(
image
,
x
,
y
,
method
):
if
not
in
I
mage
(
image
,
x
,
y
):
if
not
in
_i
mage
(
image
,
x
,
y
):
return
bgcolor
return
bgcolor
if
method
==
'nearest'
:
if
method
==
'nearest'
:
...
@@ -28,10 +28,10 @@ def pV(image, x, y, method):
...
@@ -28,10 +28,10 @@ def pV(image, x, y, method):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
from
pylab
import
linspace
,
show
,
imread
,
plot
,
array
from
pylab
import
linspace
,
show
,
imread
,
plot
,
array
"""Profile of an image along line in n points."""
def
profile
(
image
,
x0
,
y0
,
x1
,
y1
,
n
,
method
):
def
profile
(
image
,
x0
,
y0
,
x1
,
y1
,
n
,
method
):
"""Profile of an image along line in n points."""
dataset
=
zip
(
linspace
(
x0
,
x1
,
n
),
linspace
(
y0
,
y1
,
n
))
dataset
=
zip
(
linspace
(
x0
,
x1
,
n
),
linspace
(
y0
,
y1
,
n
))
return
array
([
p
V
(
image
,
x
,
y
,
method
)
for
x
,
y
in
dataset
])
return
array
([
p
v
(
image
,
x
,
y
,
method
)
for
x
,
y
in
dataset
])
a
=
imread
(
'cameraman.png'
)
a
=
imread
(
'cameraman.png'
)
for
method
in
[
'nearest'
,
'linear'
]:
for
method
in
[
'nearest'
,
'linear'
]:
...
...
modsim/ass4_sander/part2/main.c
View file @
401a095d
...
@@ -40,7 +40,7 @@ static void init_pluck(double pluck, double length, double dx) {
...
@@ -40,7 +40,7 @@ static void init_pluck(double pluck, double length, double dx) {
}
}
for
(
;
i
<
STRING_PARTS
;
i
++
)
{
for
(
;
i
<
STRING_PARTS
;
i
++
)
{
SET_Y
(
i
,
0
,
((
STRING_PARTS
-
i
)
*
dx
)
/
(
STRING_PARTS
-
ipos
));
SET_Y
(
i
,
0
,
((
length
-
i
)
*
dx
)
/
(
length
-
ipos
));
}
}
}
}
...
@@ -90,13 +90,13 @@ int main(int argc, char **argv) {
...
@@ -90,13 +90,13 @@ int main(int argc, char **argv) {
// Initialise time indices, iterations and string length.
// Initialise time indices, iterations and string length.
int
t_prev
=
0
,
t_cur
=
1
,
t_next
=
2
,
int
t_prev
=
0
,
t_cur
=
1
,
t_next
=
2
,
iterations
=
atoi
(
argv
[
2
]),
iterations
=
atoi
(
argv
[
2
]);
length
=
atoi
(
argv
[
3
]);
double
dx
=
atof
(
argv
[
4
]),
double
length
=
atof
(
argv
[
3
]),
dx
=
atof
(
argv
[
4
]),
tau
=
atof
(
argv
[
5
]);
tau
=
atof
(
argv
[
5
]);
STRING_PARTS
=
length
/
dx
;
STRING_PARTS
=
ceil
(
length
/
dx
)
+
1
;
if
(
!
(
Y
=
(
double
*
)
malloc
(
3
*
STRING_PARTS
*
sizeof
(
double
)))
)
if
(
!
(
Y
=
(
double
*
)
malloc
(
3
*
STRING_PARTS
*
sizeof
(
double
)))
)
return
2
;
return
2
;
...
@@ -114,11 +114,13 @@ int main(int argc, char **argv) {
...
@@ -114,11 +114,13 @@ int main(int argc, char **argv) {
// The string is connected at both ends.
// The string is connected at both ends.
connect_string_ends
();
connect_string_ends
();
plot
(
t_prev
);
for
(
int
i
=
0
;
i
<
iterations
;
i
++
)
{
for
(
int
i
=
0
;
i
<
iterations
;
i
++
)
{
iterate
(
tau
,
t_prev
,
t_cur
,
t_next
);
iterate
(
tau
,
t_prev
,
t_cur
,
t_next
);
SWAP
(
t_cur
,
t_next
);
SWAP
(
t_cur
,
t_next
);
SWAP
(
t_prev
,
t_next
);
SWAP
(
t_prev
,
t_next
);
plot
(
t_cur
);
//
plot(t_cur);
}
}
return
0
;
return
0
;
...
...
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