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
9fd61674
Commit
9fd61674
authored
Sep 23, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ImProc ass2: Finished assignment.
parent
98fbfd2e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
21 deletions
+25
-21
improc/ass2/transform.py
improc/ass2/transform.py
+25
-21
No files found.
improc/ass2/transform.py
View file @
9fd61674
from
interpolation
import
pv
from
interpolation
import
pv
from
pylab
import
array
,
matrix
,
zeros
,
show
,
dot
,
lstsq
,
inv
,
svd
,
subplot
,
\
from
numpy
import
array
,
matrix
,
zeros
,
dot
plot
,
figure
from
numpy.linalg.linalg
import
lstsq
,
inv
,
svd
# url: http://www.leptonica.com/affine.html
# url: http://www.leptonica.com/affine.html
...
@@ -37,7 +37,7 @@ def affine_transform(image, p1, p2, p3, width, height):
...
@@ -37,7 +37,7 @@ def affine_transform(image, p1, p2, p3, width, height):
for
x
in
xrange
(
width
):
for
x
in
xrange
(
width
):
for
y
in
xrange
(
height
):
for
y
in
xrange
(
height
):
orig_pos
=
(
A
*
array
([[
x
,
y
,
1
]]).
T
).
T
.
tolist
()[
0
]
orig_pos
=
A
*
array
([[
x
,
y
,
1
]]).
T
result
[
x
][
y
]
=
pv
(
image
,
orig_pos
[
0
],
orig_pos
[
1
],
'linear'
)
result
[
x
][
y
]
=
pv
(
image
,
orig_pos
[
0
],
orig_pos
[
1
],
'linear'
)
return
result
return
result
...
@@ -61,7 +61,7 @@ def perspective_transform(image, p1, p2, p3, p4, width, height):
...
@@ -61,7 +61,7 @@ def perspective_transform(image, p1, p2, p3, p4, width, height):
[
0
,
0
,
0
,
x4
,
y4
,
1
,
-
height
*
x4
,
-
height
*
y4
,
-
height
]])
[
0
,
0
,
0
,
x4
,
y4
,
1
,
-
height
*
x4
,
-
height
*
y4
,
-
height
]])
# Calculate transform matrix
# Calculate transform matrix
A
=
inv
(
svd
(
M
)[
2
]
.
T
[:,
-
1
].
reshape
(
3
,
3
))
A
=
inv
(
svd
(
M
)[
2
]
[
-
1
].
reshape
(
3
,
3
))
# Construct the transformed image
# Construct the transformed image
result
=
zeros
((
width
,
height
,
4
))
result
=
zeros
((
width
,
height
,
4
))
...
@@ -69,32 +69,36 @@ def perspective_transform(image, p1, p2, p3, p4, width, height):
...
@@ -69,32 +69,36 @@ def perspective_transform(image, p1, p2, p3, p4, width, height):
for
x
in
xrange
(
width
):
for
x
in
xrange
(
width
):
for
y
in
xrange
(
height
):
for
y
in
xrange
(
height
):
p
=
dot
(
A
,
array
([[
x
],
[
y
],
[
1
]]))
p
=
dot
(
A
,
array
([[
x
],
[
y
],
[
1
]]))
result
[
x
][
y
]
=
pv
(
image
,
p
[
0
]
/
p
[
2
],
p
[
1
]
/
p
[
2
],
'linear'
)
result
[
x
][
y
]
=
pv
(
image
,
p
[
1
]
/
p
[
2
],
p
[
0
]
/
p
[
2
],
'linear'
)
return
result
return
result
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
from
pylab
import
imread
,
imshow
from
pylab
import
imread
,
imshow
,
plot
,
subplot
,
show
,
axis
#image = imread('cameraman.png')
image
=
imread
(
'flyeronground.png'
)
# Affine transformation
subplot
(
221
)
image
=
imread
(
'cameraman.png'
)
half_width
=
image
.
shape
[
0
]
/
2
half_width
=
image
.
shape
[
0
]
/
2
half_height
=
image
.
shape
[
1
]
/
2
half_height
=
image
.
shape
[
1
]
/
2
M
,
N
=
image
.
shape
[:
2
]
#result = affine_transform(image, (0., half_height), (half_width, 0.),
# (image.shape[0], half_height), 128, 128)
result
=
perspective_transform
(
image
,
(
149
,
590
),
(
101
,
376
),
(
301
,
209
),
(
393
,
392
),
64
,
64
)
figure
(
1
)
subplot
(
121
)
x
=
[
0
,
half_width
,
image
.
shape
[
0
],
half_width
,
0
]
x
=
[
0
,
half_width
,
image
.
shape
[
0
],
half_width
,
0
]
y
=
[
half_height
,
0
,
half_height
,
image
.
shape
[
1
],
half_height
]
y
=
[
half_height
,
0
,
half_height
,
image
.
shape
[
1
],
half_height
]
plot
(
x
,
y
,
'-'
)
plot
(
x
,
y
,
'r-'
)
axis
([
0
,
image
.
shape
[
0
],
0
,
image
.
shape
[
1
]])
imshow
(
image
,
cmap
=
'gray'
)
imshow
(
image
,
cmap
=
'gray'
)
subplot
(
122
)
subplot
(
222
)
result
=
affine_transform
(
image
,
(
0.
,
half_height
),
(
half_width
,
0.
),
(
image
.
shape
[
0
],
half_height
),
128
,
128
)
imshow
(
result
,
cmap
=
'gray'
)
imshow
(
result
,
cmap
=
'gray'
)
# Perspective transformation
subplot
(
223
)
image
=
imread
(
'flyeronground.png'
)
x
,
y
=
zip
((
147
,
588
),
(
100
,
370
),
(
300
,
205
),
(
392
,
392
),
(
147
,
588
))
plot
(
x
,
y
,
'r-'
)
imshow
(
image
)
subplot
(
224
)
result
=
perspective_transform
(
image
,
(
147
,
588
),
(
392
,
392
),
(
100
,
370
),
\
(
300
,
205
),
100
,
150
)
imshow
(
result
)
show
()
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