# Introduction to Computer Vision by wangnianwu

VIEWS: 0 PAGES: 66

• pg 1
```									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

T(w, z)

z                        y
w   f(w, z)              x   g(x, y )

• Transformation: (x, y) = T{(w, z)}
8
Coordinate Mapping

-1
T (x, y)

z                          y
w   f(w, z)               x   g(x, y )

• Transformation: (w, z) = T-1{(x, y)}
9
(w, z) = (2x, 2y)
Textbook
Page 280
(x, y) = (w/2, z/2)
Figure 6.2

Transformations:
(x, y) = T{(w, z)} = (w/2, z/2)
(w, z) = T-1{(x, y)} = (2x, 2y)

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’= x + 4
y’= y - 1                 y

x    -3   -3     -2
y     3    1      1

0        x
x’    1    1     2
y’    2    0     0

17
Rotation
theta = 90o               y

x      -3   -3     -2
y       3    1      1

0        x
x’     -5   -3     -3
y’      1    1      2

18
Reflection
y

x    -3   -3   -2
y     3    1    1

0        x
x’   -3   -3   -2
y’   -3   -1   -1

19
Scaling
y

x    -3   -3   -2
y     3    1    1

0        x
x’   -3   -3   -2
y’   -3   -1   -1

20
Scaling
• multiplying each of its
coordinates by a scalar       y

x    -3   -3   -2
y     3    1    1
x
0

x’   -3   -3   2
y’    4    1   1
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)

Polynomial Format                 Matrix Format

a0 b0 
x'  a0 x  a1 y        x' y'          * x    y
y'  b0 x  b1 y                  a1 b1 
Transformation
Matrix T

24
Affine Transformations
Recall:
x’ = Tx(x, y)        y’=Ty(x, y)

Polynomial Format                     Matrix Format

x'  a0 x  a1 y  a2                a0 b0 0
x' y' 1   a1 b1 0 * x
                y 1
y'  b0 x  b1 y  b2
a2 b2 1
        
Transformation
Matrix T
25
Affine Transformations
• Perceptually, Affine Transformations are
linear combinations of
– Translation
– Rotation
– Scaling

26
Linear Transformations
• Rotation              y
x, y             x, y 


x
0

 x   cos         sin    x 
 
 y   sin                 * 
                  cos    y 
  
27
Linear Transformations
• Scaling      y

x
0

 x   s x   0   x   sx x 
 
 y   0            y s y
 *   
            sy     y 
             
28
Linear Transformations
• Reflection                  y
along X-axis

x
0

 x   1 0   x   x 
 
 y   0  1 *  y     y 
    
               
29
Linear Transformations
• Reflection        y
along Y-axis

x
0

 x    1 0   x    x 
 
 y   0 1  *  y    y 
    
                
30
Linear Transformations
• Shearing           y
along X-axis

x
0

 x   1 d  x   x  dy 
 y   0 1  y    y 
                     
                      
31
Linear Transformations
• Shearing
along Y-axis       y

x
0

 x   1 0  x   x 
 y   d 1  y    y  dx 
                       
                        
32
Affine Transformations
• Rotation                      y

x, y                  x, y 

x
0

 x   cos       sin        0  x 
                                 
 y    sin        cos      0 * y 
1  0                          1  1 
                      0          
33
Affine Transformations
• Scaling              y

x
0

 x   s x   0    0   x   sx x 
                                
 y    0   sy   0 * y    sy y 
1 0              1  1   1 
            0                   
34
Affine Transformations
• Shearing                y

x
0

 x   1 d 0   x   x  dy 
                          
 y    0 1 0  *  y    y 
 1  0 0 1  1   1 
                          
35
Affine Transformations
• Reflection              y

x
0

 x   1 0 0   x   x 
                    
 y    0  1 0  *  y     y 
 1  0 0 1  1   1 
                    
36
Affine Transformations
• Translation            y

x
0

 x   1 0 t x   x   x  t x 
                                  
 y    0 1 t y  *  y    y  t y 
 1  0 0 1   1   1 
                                  
37
Summary
Translation                                Scaling

 x   1 0 t x   x                 x   s x     0        0  x 
                                                           
 y    0 1 t y  *  y             y    0     sy       0 * y 
 1  0 0 1   1                    1 0                    1  1 
                                               0           

Rotation                                   Shearing
 x   cos       sin    0  x      x   1            shx    0  x 
                                                                
 y    sin    cos      0 * y     y    shy        1      0 * y 
1  0                      1  1     1  0                      1  1 
                  0                                   0         

38
Textbook
Page 286
Table 6.1

Summary

39
Projective Transformations

40
Vanishing
Point     Horizon
Line     Vanishing
Point

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
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
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
Translation                                Scaling
 x   1 0 t x   x                 x   s x     0        0  x 
                                                           
 y    0 1 t y  *  y             y    0     sy       0 * y 
 1  0 0 1   1                    1 0                    1  1 
                                               0           

Rotation                                   Shearing
 x   cos       sin    0  x      x   1            shx    0  x 
                                                                
 y    sin    cos      0 * y     y    shy        1      0 * y 
1  0                      1  1     1  0                      1  1 
                  0                                   0         

66

```
To top