EECE/CS 253 Image Processing: Lecture Notes: Warping and Rotating Images
EECE/CS 253 Image Processing: Lecture Notes: Warping and Rotating Images
EECE/CS 253 Image Processing: Lecture Notes: Warping and Rotating Images
Lecture Notes: Warping and Rotating Images Lecture Notes Richard Alan Peters II
Department of Electrical Engineering and Computer Science
Fall Semester 2011
This work is licensed under the Creative Commons Attribution-Noncommercial 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.
Geometric Remapping
Input Image
Warping Function
Interpolation Function
Output Image
2011-11-07
Geometric Remapping
1. Assume the input image, I, has infinite spatial resolution. 2. Calculate the size, RoutCoutB, of the output image, J, and allocate it. 3. Create an image map (a warping function, ) as follows: a) Allocate an RoutCout2 array, . b) For every pixel location (r,c) in J find the corresponding real-valued pixel location (rf ,cf) in I. c) Set (r,c,1) = rf and set (r,c,2) = cf . 4. Create an interpolation function, , that generates a pixel value from the values of I on a neighborhood, N(rf ,cf). 5. Then set J(r,c) = {I; N(rf ,cf)}.
2011-11-07 1999-2011 by Richard Alan Peters II 3
Photo: JBUK_Planet, http://www.flickr.com/people/jbuk_planet/, Highclere Castle, Highclere Park, Newbury RG20 9RN, England, http://www.highclerecastle.co.uk/, August 26, 2007, Kodak DX6440
(52, 632)
(913, 624)
2011-11-07
(52, 632)
(913, 624)
2011-11-07
(52, 632)
(403, 652)
(913, 624)
Y = HX
where
x1 x2 x p X = x1 x 2 x p = y y y 1 2 p u1 u2 u p Y = y1 y 2 y p = v v v 1 2 p
-1
and
h h H = 11 12 h21 h22
10
HX
where
X = x1 x 2 Y = y1 y 2
-1
This does not work very well. x1 x2 x p This is x p = a 2D linear transform. y y y 1need What we p 2 is a 3D affine h11 H = transform. A 3rd dimension and h 21 enables u us to model more geu u 1 2 p we use neral y p = projections. Thus v v v 1 2 p 3D homogeneous coordinates.
h12 h22
y i = Hxi
ki ui y i = ki vi ki
2011-11-07
12
Y = HX
H is 33.
Remapped pixel locations in homogeneous form written as a 33 matrix. Note that usually each ki is different.
k pu p k pvp k p
13
ui =
h11 xi + h12 yi + h13 ui = h31 xi + h32 yi + 1 vi = h21 xi + h22 yi + h23 h31 xi + h32 yi + 1
Divide both numerator and denominator by h33. Then relabel the coefficients.
2011-11-07
14
15
u1 v1 u2 v2 y pu p u p y p v p v p y1u1 y1v1 y2 u 2 y2 v2
Collect p 4 pixel locations, remap them as desired, and form the matrix A.
2011-11-07
If the previous def of A led to H that gave wrong results, try this one:
2011-11-07
V = v1 v 2 v p
s1 0 S = 0
0 s2 0
0 0 s p
h = vk
2011-11-07
2011-11-07
cJ -1 J (rJ , cJ ) = I N H rJ 1
20
2011-11-07
2011-11-07
21
Image Rotation
image size:
R in A = tan C in
1
2 2 D = R in + C in
length of diagonal:
2011-11-07
22
Image Rotation
angle of rotation: rotation matrix: cos sin () = - sin cos transforms input image to output image cdts. cdts.1
R in 0 C in 0
(R
in0
, C in0 =
) (
1 2
R in + 1, 1 2C in + 1
)
23
2011-11-07
Image Rotation
Compute the dimensions of the output image: number of rows.
2011-11-07
24
Image Rotation
Compute the dimensions of the output image: number of columns.
2011-11-07
25
Image Rotation
The output dimension calculation depends on the value of as follows:
If 0 < 90: If 90 < 180:
2011-11-07
26
Image Rotation
Allocate an output image with dimensions (Rout,Cout), where1
R out 0 C out 0
and Cout below are valid for 0 < 90. Otherwise see slide 7.
1999-2011 by Richard Alan Peters II 27
2011-11-07
Image Rotation
cos - sin -1 () = sin cos = (- ) Work backward. For every output loc. (r,c) select an input loc. (rf ,cf) by rotating (r,c) around the image center by -. r F ( r , c,:) = f c f r - R out 0 = -1 () c - Cout 0 R + in 0 C in 0
2011-11-07 1999-2011 by Richard Alan Peters II 28
R out 0 C out 0
Image Rotation
Rotating the input image by is equivalent to rotating the ouput image by -. r - R out 0 R in 0 F ( r , c,:) = -1 () + c - Cout 0 C in 0
2011-11-07 1999-2011 by Richard Alan Peters II 29
Image Rotation
After rotation by -, J(r,c) is in nearly the same position as I(rf,cf). r F ( r , c,:) = f c f r - R out 0 = -1 () c - Cout 0 R + in 0 C in 0
2011-11-07 1999-2011 by Richard Alan Peters II 30
Image Rotation
After rotation by -, J(r,c) is in nearly the same position as I(rf,cf). r F ( r , c,:) = f c f r - R out 0 = -1 () c - Cout 0 R + in 0 C in 0
2011-11-07 1999-2011 by Richard Alan Peters II 31
Image Rotation
After rotation by -, J(r,c) is in nearly the same position as I(rf,cf). r F ( r , c,:) = f c f r - R out 0 = -1 () c - Cout 0 R + in 0 C in 0
2011-11-07 1999-2011 by Richard Alan Peters II 32
Image Rotation
J (r , c) = Q {I; N (rf , c f )} .
Interpolation: The output pixel value is (usually) a function of the values on a neighborhood a set of pixels that surrounds (rf ,cf ). Bilinear Interp. uses a 22 neighborhood, bicubic uses a 44. Nearest neighbor is simply, J(r,c) = I(ri ,ci ) where (ri ,ci ) = round(rf ,cf ).
2011-11-07 1999-2011 by Richard Alan Peters II 33
Bilinear Bicubic
36
Bilinear Bicubic
2011-11-07
1 2
= tan 1 ( cr = sin 1
), ( ).
out out
cin = d cos ( )
rin = d sin ( )
2 d= d 0
2011-11-07
38
2011-11-07
39