Вы находитесь на странице: 1из 21

EECE\CS 253 Image Processing

Richard Alan Peters II



Department of Electrical Engineering and
Computer Science

Fall Semester 2007
Lecture Notes
Lecture Notes: Rotating Images
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.
6/25/2012 2 6/25/2012 2 1999-2007 by Richard Alan Peters II
Geometric Remapping
Input Image
Warping Function
Interpolation Function
Output Image
6/25/2012 3 6/25/2012 3 1999-2007 by Richard Alan Peters II
Geometric Remapping
1. Assume the input image, I, has infinite spatial resolution.
2. Calculate the size, R
out
C
out
B, of the output image, J, and
allocate it.
3. Create an image map (a warping function, u) as follows:
a) Allocate an R
out
C
out
2 array, u.
b) For every pixel location (r,c) in J find the corresponding
real-valued pixel location (r
f
,c
f
) in I.
c) Set u(r,c,1) = r
f
and set u(r,c,2) = c
f
.
4. Create an interpolation function, O, that generates a pixel
value from the values of I on a neighborhood, N(r
f
,c
f
).
5. Then set J(r,c) = O{I; N(r
f
,c
f
)}.
6/25/2012 4 6/25/2012 4 1999-2007 by Richard Alan Peters II
Image Rotation
| | ( ) I size , ,
in in
= B C R
2
in
2
in
C R D + =
(
(

=

in
in 1
tan
C
R
A
image size:
aspect angle:
length of diagonal:
6/25/2012 5 6/25/2012 5 1999-2007 by Richard Alan Peters II
Image Rotation
( )

( ) 1 , 1 ,
in 2
1
in 2
1
in0 in0
+ + = C R C R
(

0 in
0 in
C
R
( )
(

= P
cos sin
sin cos

angle of rotation: u
rotation matrix:
( )
(

+
(

P =
(

out0
out0
in0 in
in0 in

R
R
C c
R r
c
r
transforms input image cdts.
1

to output image cdts.
1
cdts. measured w.r.t. the center of the image:
6/25/2012 6 6/25/2012 6 1999-2007 by Richard Alan Peters II
Image Rotation
Compute the dimensions
of the output image:
number of rows.
if 0 < u s 90.
( )
( ), round sin D
out A
R + =
6/25/2012 7 6/25/2012 7 1999-2007 by Richard Alan Peters II
Image Rotation
Compute the dimensions
of the output image:
number of columns.
( )
( )
A
C cos D round
out
=
if 0 < u s 90.
6/25/2012 8 6/25/2012 8 1999-2007 by Richard Alan Peters II
Image Rotation
The output dimension calculation depends on the value of u as follows:
If 0 s u < 90:
( )
( ), round sin D
out A
R + =
( )
( ). round cos D
out A
C =
If

90 s u < 0:
( )
( ), round sin D
out A
R =
( )
( ). round cos D
out A
C + =
If 90 s u < 180:
( )
( ), round 90 cos D
out A
R =
( )
( ). round 90 sin D
out A
C + =
If

180 s u <

90:
( )
( ), round 90 cos D
out A
R + + =
( )
( ). round 90 sin D
out A
C + =
6/25/2012 9 6/25/2012 9 1999-2007 by Richard Alan Peters II
Image Rotation
( )

( ). 1 , 1
,
out 2
1
out 2
1
out0 out0
+ +
=
C R
C R
(

0 out
0 out
C
R
Allocate an output
image with dimensions
(R
out
,C
out
), where
1

( )
( )
A
R sin D round
out
+ =
( )
( )
A
C cos D round
out
=
and center point
1
R
out
and C
out
below are valid for 0 < u s 90. Otherwise see slide 7.
6/25/2012 10 6/25/2012 10 1999-2007 by Richard Alan Peters II
Image Rotation
( )
( )
(

+
(

P =
(

= u

0 in
0 in
0 out
0 out 1

: , ,
C
R
C c
R r
c
r
c r
f
f
( )
( )
cos sin
sin cos

1
P =
(


= P

Work backward. For


every output loc. (r,c)
select an input loc. (r
f
,c
f
)
by rotating (r,c) around
the image center by -u.
(

0 out
0 out
C
R
6/25/2012 11 6/25/2012 11 1999-2007 by Richard Alan Peters II
( ) ( )
(

+
(

P = u

0 in
0 in
0 out
0 out 1
: , ,
C
R
C c
R r
c r
Image Rotation
Rotating the input image
by u is equivalent to
rotating the ouput image
by -u.
6/25/2012 12 6/25/2012 12 1999-2007 by Richard Alan Peters II
Image Rotation
( )
( )
(

+
(

P =
(

= u

0 in
0 in
0 out
0 out 1

: , ,
C
R
C c
R r
c
r
c r
f
f
After rotation by -u,
J(r,c) is in nearly the
same position as
I(r
f
,c
f
).
6/25/2012 13 6/25/2012 13 1999-2007 by Richard Alan Peters II
Image Rotation
( )
( )
(

+
(

P =
(

= u

0 in
0 in
0 out
0 out 1

: , ,
C
R
C c
R r
c
r
c r
f
f
After rotation by -u,
J(r,c) is in nearly the
same position as
I(r
f
,c
f
).
6/25/2012 14 6/25/2012 14 1999-2007 by Richard Alan Peters II
Image Rotation
( )
( )
(

+
(

P =
(

= u

0 in
0 in
0 out
0 out 1

: , ,
C
R
C c
R r
c
r
c r
f
f
After rotation by -u,
J(r,c) is in nearly the
same position as
I(r
f
,c
f
).
6/25/2012 15 6/25/2012 15 1999-2007 by Richard Alan Peters II
Image Rotation
( ) ( ) { }. , I; , J
f f
c r c r N O =
Interpolation:
The output pixel value is
(usually) a function of the
values on a neighborhood
a set of pixels that
surrounds (r
f
,c
f
).
Bilinear Interp. uses a 22
neighborhood, bicubic
uses a 44.
Nearest neighbor is simply,
J(r,c) = I(r
i
,c
i
) where
(r
i
,c
i
) = round(r
f
,c
f
).
6/25/2012 16 6/25/2012 16 1999-2007 by Richard Alan Peters II
Image Rotation with Interpolation
Original image: San Francisco financial district
6/25/2012 17 6/25/2012 17 1999-2007 by Richard Alan Peters II
Image Rotation with Nearest Neighbor Interpolation
Bicubic Nearest Neighbor Nearest Neighbor Bilinear
6/25/2012 18 6/25/2012 18 1999-2007 by Richard Alan Peters II
Image Rotation with Bilinear Interpolation
Nearest Neighbor Bilinear Bilinear Bicubic
6/25/2012 19 6/25/2012 19 1999-2007 by Richard Alan Peters II
Image Rotation with Bicubic Interpolation
Bilinear Bicubic Bicubic Nearest Neighbor
6/25/2012 20 6/25/2012 20 1999-2007 by Richard Alan Peters II
Example of Warping: Map Image to Sphere
( )
0 out out
1
min , .
2
R C =
( )
( )
out
out
0
2 2
out out
1
1
,
tan ,
sin .
r
c
r c

u
|

= +
=
=
( )
0 in in
1
max , .
2
d R C =
( )
( )
2
0
in
in
sin
cos
d d
r d
c d
t
|
u
u
=
=
=
For each output pixel,
For the output image, For the input image,
For each output pixel,
the input pixel loc is,
6/25/2012 21 6/25/2012 21 1999-2007 by Richard Alan Peters II
Example of Warping: Map Image to Sphere
d: radial distance
from center of
input image.
: same for
output image.

Вам также может понравиться