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
401a095d
Commit
401a095d
authored
13 years ago
by
Sander Mathijs van Veen
Browse files
Options
Downloads
Patches
Plain Diff
improc: WIP on ass2.
parent
1a0c8b6c
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/ass2/affine.py
+66
-0
66 additions, 0 deletions
improc/ass2/affine.py
improc/ass2/interpolation.py
+5
-5
5 additions, 5 deletions
improc/ass2/interpolation.py
modsim/ass4_sander/part2/main.c
+8
-6
8 additions, 6 deletions
modsim/ass4_sander/part2/main.c
with
79 additions
and
11 deletions
improc/ass2/affine.py
0 → 100644
+
66
−
0
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
)
This diff is collapsed.
Click to expand it.
improc/ass2/interpolation.py
+
5
−
5
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
'
]:
...
...
This diff is collapsed.
Click to expand it.
modsim/ass4_sander/part2/main.c
+
8
−
6
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
;
...
...
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