Sync.

parent 401a095d
from interpolation import in_image, pv from interpolation import pv
from numpy import array, zeros from numpy import array, zeros
from numpy.linalg import lstsq from numpy.linalg import lstsq, inv
# url: http://www.leptonica.com/affine.html # url: http://www.leptonica.com/affine.html
...@@ -28,7 +28,8 @@ def affine_transform(image, p1, p2, p3, width, height): ...@@ -28,7 +28,8 @@ def affine_transform(image, p1, p2, p3, width, height):
# Calculate transform matrix # Calculate transform matrix
p = lstsq(M, q)[0] p = lstsq(M, q)[0]
T = p.reshape(2, 3).T T = p.reshape(2, 3).T
T = inv(T)
# Construct the transformed image # Construct the transformed image
result = zeros((width, height)) result = zeros((width, height))
...@@ -45,7 +46,16 @@ def affine_transform(image, p1, p2, p3, width, height): ...@@ -45,7 +46,16 @@ def affine_transform(image, p1, p2, p3, width, height):
orig_pos = array([x, y, 1]).reshape(3, 1) * T orig_pos = array([x, y, 1]).reshape(3, 1) * T
#print x,y, tmp #print x,y, tmp
#result[y][x] = print orig_pos, len(orig_pos)
# XXX Why is orig_pos in the format listed below?
#
# |g h|
# |i j|
# |k l|
#
result[y][x] = pv(image, orig_pos[0], orig_pos[1], 'linear')
return result return result
...@@ -58,7 +68,7 @@ if __name__ == '__main__': ...@@ -58,7 +68,7 @@ if __name__ == '__main__':
half_height = image.shape[1] / 2 half_height = image.shape[1] / 2
M, N = image.shape M, N = image.shape
# TODO: validate MxN -> width x height # TODO: validate MxN -> width x height
result = affine_transform(image, (0., 0.), (0., half_height), result = affine_transform(image, (0., 0.), (0., half_height),
(half_width, half_height), M, N) (half_width, half_height), M, N)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment