Upload
mujeeb-abdullah
View
4
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Geometric
Citation preview
Introduction to Computer VisionLecture 10
Chapter 6: Geometric Transformations
Speaker: Yuheng WangEmail: [email protected]
Date: 01/26 /2012
1
Outline
• Geometric Transformation Theory– Linear transformations– Affine transformations– Projective transformations
• Matlab Implementation
2
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 280Figure 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
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
Scaling
x’ -3 -3 2
y’ 4 1 1
x -3 -3 -2
y 3 1 1x
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’ = Tx(x, y)
y’=Ty(x, y)
23
Linear Transformations Recall:
x’ = Tx(x, y) y’=Ty(x, y)
yaxax 10' ybxby 10'
yxba
bayx *''
11
00
Matrix FormatPolynomial Format
Transformation Matrix T
24
Affine Transformations
210' ayaxax
210' bybxby 1*
1
0
0
1''
22
11
00
yx
ba
ba
ba
yx
Matrix FormatPolynomial Format
Transformation Matrix T
Recall:
x’ = Tx(x, y) y’=Ty(x, y)
25
Affine Transformations
• Perceptually, Affine Transformations are linear combinations of – Translation – Rotation– Scaling
26
Summary
1
*
100
00
00
1
y
x
s
s
y
x
y
x
1
*
100
0cossin
0sincos
1
y
x
y
x
1
*
100
01
01
1
y
x
sh
sh
y
x
y
x
1
*
100
10
01
1
y
x
t
t
y
x
y
x
Translation Scaling
ShearingRotation
38
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, clcIm = 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 Rotationtheta = 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 29052
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 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
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
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