You are on page 1of 66

Introduction to Computer Vision

Lecture 10
Chapter 6: Geometric Transformations

Speaker: Yuheng Wang
Email: yxw9636@rit.edu
Date: 01/26 /2012
1
Outline
Geometric Transformation Theory
Linear transformations
Affine transformations
Projective transformations

Matlab Implementation

2
Geometric Transformations
Original Image
3
Geometric Transformations
Scaling
4
Geometric Transformations
Rotation
5
Geometric Transformations
Affine Transformation
6
Geometric Transformations
Projective Transformation
7
Coordinate Mapping
Transformation: (x, y) = T{(w, z)}
f(w, z) g(x, y )
T(w, z)
x
y
w
z
8
Coordinate Mapping
Transformation: (w, z) = T
-1
{(x, y)}
f(w, z) g(x, y )
w
x
T
-1
(x, y)
z y
9
Transformations:
(x, y) = T{(w, z)} = (w/2, z/2)
(w, z) = T
-1
{(x, y)} = (2x, 2y)

(x, y) = (w/2, z/2)
(w, z) = (2x, 2y)
Textbook
Page 280
Figure 6.2
10
Linear Transformations
An operation than change the figure in
some way, can be either or a
combination of:
Translation: slide
Rotation: turn
Reflection: flip
Reference:
http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/geometry//geo-tran.html
11
Translation
Move the object without changing the image
size and orientation
12
Rotation
Turn the object about around certain fixed
point (the rotation center)
Rotation
Center
13
Reflection
Flip the object over a line (the line of
reflection)
Line of
Reflection
14
Reflection
15
Method to implement transformations
Find coordinates (x, y) of the original image
Use the transformation rule to change
original coordinates (x, y) to (x, y)
Show the new image using (x, y)
16
Translation
x 1 1 2
y 2 0 0
x -3 -3 -2
y 3 1 1
x
y
0
x= x + 4
y= y - 1

17
Rotation
x -5 -3 -3
y 1 1 2
x -3 -3 -2
y 3 1 1
x
y
0
theta = 90
o
18
Reflection
x -3 -3 -2
y -3 -1 -1
x -3 -3 -2
y 3 1 1
x
y
0
19
Scaling
x -3 -3 -2
y -3 -1 -1
x -3 -3 -2
y 3 1 1
x
y
0
20
Scaling
x -3 -3 2
y 4 1 1
x -3 -3 -2
y 3 1 1
x
y
0
multiplying each of its
coordinates by a scalar
21
Overall workflow
Find coordinates (x, y) of the original image
Use the transformation rule to change
original coordinates (x, y) to (x, y)
Show the new image using (x, y)
22
Mathematical Definition

A geometric transformation is a matrix(vector)
T that maps the pixel (x, y) to a new position
(x, y)
x = T
x
(x, y)
y=T
y
(x, y)

23
Linear Transformations
Recall:
x = T
x
(x, y) y=T
y
(x, y)
y a x a x
1 0
' + =
y b x b y
1 0
' + =
| | | | y x
b a
b a
y x * ' '
1 1
0 0
(

=
Matrix Format Polynomial Format
Transformation
Matrix T
24
Affine Transformations
2 1 0
' a y a x a x + + =
2 1 0
' b y b x b y + + =
| | | | 1 *
1
0
0
1 ' '
2 2
1 1
0 0
y x
b a
b a
b a
y x
(
(
(

=
Matrix Format Polynomial Format
Transformation
Matrix T
Recall:
x = T
x
(x, y) y=T
y
(x, y)
25
Affine Transformations
Perceptually, Affine Transformations are
linear combinations of
Translation
Rotation
Scaling

26
Linear Transformations
|
|
.
|

\
|
|
|
.
|

\
|

=
|
|
.
|

\
|
'
'
y
x
y
x
*
cos sin
sin cos
u u
u u
( ) y x,
( ) y x
' '
,
x
y
0
u
Rotation
27
Linear Transformations
|
|
.
|

\
|
=
|
|
.
|

\
|
|
|
.
|

\
|
=
|
|
.
|

\
|
'
'
y s
x s
y
x
s
s
y
x
y
x
y
x
*
0
0
x
y
0
Scaling
28
Linear Transformations
Reflection
along X-axis



|
|
.
|

\
|

=
|
|
.
|

\
|
|
|
.
|

\
|

=
|
|
.
|

\
|
'
'
y
x
y
x
y
x
*
1 0
0 1
x
y
0
29
Linear Transformations
Reflection
along Y-axis

|
|
.
|

\
|

=
|
|
.
|

\
|
|
|
.
|

\
|

=
|
|
.
|

\
|
'
'
y
x
y
x
y
x
*
1 0
0 1
x
y
0
30
Linear Transformations
Shearing
along X-axis

|
|
.
|

\
|
+
=
|
|
.
|

\
|
|
|
.
|

\
|
=
|
|
.
|

\
|
'
'
y
dy x
y
x d
y
x
1 0
1
x
y
0
31
Linear Transformations
Shearing
along Y-axis

|
|
.
|

\
|
+
=
|
|
.
|

\
|
|
|
.
|

\
|
=
|
|
.
|

\
|
'
'
dx y
x
y
x
d y
x
1
0 1
x
y
0
32
Affine Transformations
Rotation



|
|
|
.
|

\
|
|
|
|
.
|

\
|

=
|
|
|
.
|

\
|
'
'
1
*
1 0 0
0 cos sin
0 sin cos
1
y
x
y
x
u u
u u
( ) y x,
( ) y x
' '
,
x
y
0
33
Affine Transformations
Scaling
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
1 1
*
1 0 0
0 0
0 0
1
y s
x s
y
x
s
s
y
x
y
x
y
x
x
y
0
34
Affine Transformations
Shearing


|
|
|
.
|

\
|
+
=
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
1 1
*
1 0 0
0 1 0
0 1
1
y
dy x
y
x d
y
x
x
y
0
35
Affine Transformations
Reflection
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
1 1
*
1 0 0
0 1 0
0 0 1
1
y
x
y
x
y
x
x
y
0
36
Affine Transformations
Translation

|
|
|
.
|

\
|
+
+
=
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
1 1
*
1 0 0
1 0
0 1
1
y
x
y
x
t y
t x
y
x
t
t
y
x
x
y
0
37
Summary
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
1
*
1 0 0
0 0
0 0
1
y
x
s
s
y
x
y
x
|
|
|
.
|

\
|
|
|
|
.
|

\
|

=
|
|
|
.
|

\
|
'
'
1
*
1 0 0
0 cos sin
0 sin cos
1
y
x
y
x
u u
u u
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
1
*
1 0 0
0 1
0 1
1
y
x
sh
sh
y
x
y
x
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
1
*
1 0 0
1 0
0 1
1
y
x
t
t
y
x
y
x
Translation Scaling
Shearing Rotation
38
Textbook
Page 286
Table 6.1
Summary
39
Projective Transformations
40
Vanishing
Point
Vanishing
Point
Horizon
Line
41
Matlab Implementation
Transformation Techniques
Affine Transformations
Projective Transformations

Matlab Implementation
function maketform
function imtransform

42
help maketform
maketform Create spatial transformation structure (TFORM).

T = maketform(TRANSFORMTYPE,...) creates a
multidimensional spatial transformation structure (a 'TFORM
struct') that can be used with TFORMFWD, TFORMINV,
FLIPTFORM, IMTRANSFORM, or TFORMARRAY. TRANSFORMTYPE
can be 'affine', 'projective', 'custom', 'box', or 'composite'. Spatial
transformations are also called geometric transformations.



43
Several Forms
T = maketform('affine',A);
T = maketform('affine',U,X);
T = maketform('projective',A);
T = maketform('projective',U,X);
T =
maketform('custom',NDIMS_IN,NDIMS_OUT,
FORWARD_FCN,INVERSE_FCN, TDATA);

44
T = maketform('custom',NDIMS_IN, NDIMS_OUT,
FORWARD_FCN,INVERSE_FCN, TDATA
Parameters
NDIMS_IN and NDIMS_OUT are the numbers of input
and output dimensions.
FORWARD_FCN and INVERSE_FCN are function
handles to forward and inverse functions.
TDATA can be any MATLAB array and is typically used
to store parameters of the custom transformation. It
is accessible to FORWARD_FCN and INVERSE_FNC via
the "tdata" field of T.
45
help imtransform
imtransform Apply 2-D spatial transformation to
image.
B = imtransform(A,TFORM) transforms the image
A according to the 2-D spatial transformation
defined by TFORM, which is a tform structure as
returned by MAKETFORM or CP2TFORM. If
ndims(A) > 2, such as for an RGB image, then the
same 2-D transformation is automatically applied
to all 2-D planes along the higher dimensions.

46
clear all, close all, clc
Im = checkerboard(50);
figure, imshow(Im), axis on;
title('Original Checkerboard');

47
Im = imread('cameraman.tif');
figure, imshow(Im), axis on;
title(Fig.1. Original Gray Scale Image');
axis on
48
Matlab for Scaling
sx=0.5;
sy=1;
Tscale=[sx 0 0; 0 sy 0; 0 0 1];
tScale=maketform('affine',Tscale);
ImScale=imtransform(Im, tScale);
figure, imshow(ImScale), axis on;
title('Scaled Checkerboard');

Textbook
Page 289
49
Matlab for Scaling
50
Scaling
51
Matlab for Rotation
theta = pi/6;
Trot = [cos(theta),sin(theta),0;
-sin(theta),cos(theta),0;
0, 0, 1];
tRot = maketform('affine',Trot);
ImRot = imtransform(Im, tRot);
figure, imshow(ImRot), axis on;
title('Rotated Checkerboard');


Textbook
Page 290
52
Matlab for Rotation
53
Rotation
54
Matlab for Shearing
shx=2;
shy=3;
Tshear=[1 shx 0;
shy 1 0;
0 0 1];
tShear=maketform('affine',Tshear);
ImShear=imtransform(Im,tShear);
figure, imshow(ImShear),axis on;
title('Sheared Checkerboard');

55
Matlab for Shearing
56
Matlab for Shearing
57
Matlab for Projection
Tpoj=[0.4788, 0.0135, -0.0009;
0.0135, 0.4788, -0.0009;
0.5059, 0.5059, 1];
tPoj=maketform('projective',Tpoj);
ImPoj=imtransform(Im,ImPoj);
figure, imshow(ImPoj), axis on;
title('Projected Checkerboard');


Textbook
Page 291
58
Matlab for Projection
59
Projection
60
Affine Transformation Example
Im = imread('cameraman.tif');
T = maketform('affine',[.5 0 0; .5 2 0; 0 0 1]);
tformfwd([10 20],T);
ImTrans= imtransform(Im,T);
figure, imshow(Im), axis on;
figure, imshow(ImTrans), axis on;
61
Result
62
Textbook
Page 309
Table 6.2
63
Textbook
Page 316
Table 6.3
64
Take home assignments
Know
Concepts of Affine/ Projective transformations
Transformation Matrices

Practice
Play with different transformation matrices T and see
how they are used in image transformations

Master
Function maketform and function imtransform
How they are implemented in Matlab



65
Take Home Message
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
1
*
1 0 0
0 0
0 0
1
y
x
s
s
y
x
y
x
|
|
|
.
|

\
|
|
|
|
.
|

\
|

=
|
|
|
.
|

\
|
'
'
1
*
1 0 0
0 cos sin
0 sin cos
1
y
x
y
x
u u
u u
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
1
*
1 0 0
0 1
0 1
1
y
x
sh
sh
y
x
y
x
|
|
|
.
|

\
|
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
'
'
1
*
1 0 0
1 0
0 1
1
y
x
t
t
y
x
y
x
Translation Scaling
Shearing Rotation
66

You might also like