Top Banner
Introduction to Computer Vision Lecture 10 Chapter 6: Geometric Transformations Speaker: Yuheng Wang Email: [email protected] Date: 01/26 /2012 1
66

CV_Lec10_Geometric_Transform.ppt

Nov 29, 2015

Download

Documents

Mujeeb Abdullah

Geometric
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CV_Lec10_Geometric_Transform.ppt

Introduction to Computer VisionLecture 10

Chapter 6: Geometric Transformations

Speaker: Yuheng WangEmail: [email protected]

Date: 01/26 /2012

1

Page 2: CV_Lec10_Geometric_Transform.ppt

Outline

• Geometric Transformation Theory– Linear transformations– Affine transformations– Projective transformations

• Matlab Implementation

2

Page 3: CV_Lec10_Geometric_Transform.ppt

Geometric Transformations

• Original Image

3

Page 4: CV_Lec10_Geometric_Transform.ppt

Geometric Transformations

• Scaling

4

Page 5: CV_Lec10_Geometric_Transform.ppt

Geometric Transformations

• Rotation

5

Page 6: CV_Lec10_Geometric_Transform.ppt

Geometric Transformations

• Affine Transformation

6

Page 7: CV_Lec10_Geometric_Transform.ppt

Geometric Transformations

• Projective Transformation

7

Page 8: CV_Lec10_Geometric_Transform.ppt

Coordinate Mapping

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

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

T(w, z)

x

y

w

z

8

Page 9: CV_Lec10_Geometric_Transform.ppt

Coordinate Mapping

• Transformation: (w, z) = T-1{(x, y)}

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

T-1 (x, y)

z y

9

Page 10: CV_Lec10_Geometric_Transform.ppt

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

Page 11: CV_Lec10_Geometric_Transform.ppt

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

Page 12: CV_Lec10_Geometric_Transform.ppt

Translation

• Move the object without changing the image size and orientation

12

Page 13: CV_Lec10_Geometric_Transform.ppt

Rotation

• Turn the object about around certain fixed point (the rotation center)

Rotation

Center13

Page 14: CV_Lec10_Geometric_Transform.ppt

Reflection

• Flip the object over a line (the line of reflection)

Line of Reflection

14

Page 15: CV_Lec10_Geometric_Transform.ppt

Reflection

15

Page 16: CV_Lec10_Geometric_Transform.ppt

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

Page 17: CV_Lec10_Geometric_Transform.ppt

Translation

x’ 1 1 2

y’ 2 0 0

x -3 -3 -2

y 3 1 1

x

y

0

x’= x + 4y’= y - 1

17

Page 18: CV_Lec10_Geometric_Transform.ppt

Rotation

x’ -5 -3 -3

y’ 1 1 2

x -3 -3 -2

y 3 1 1

x

y

0

theta = 90o

18

Page 19: CV_Lec10_Geometric_Transform.ppt

Reflection

x’ -3 -3 -2

y’ -3 -1 -1

x -3 -3 -2

y 3 1 1

x

y

0

19

Page 20: CV_Lec10_Geometric_Transform.ppt

Scaling

x’ -3 -3 -2

y’ -3 -1 -1

x -3 -3 -2

y 3 1 1

x

y

0

20

Page 21: CV_Lec10_Geometric_Transform.ppt

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

Page 22: CV_Lec10_Geometric_Transform.ppt

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

Page 23: CV_Lec10_Geometric_Transform.ppt

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

Page 24: CV_Lec10_Geometric_Transform.ppt

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

Page 25: CV_Lec10_Geometric_Transform.ppt

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

Page 26: CV_Lec10_Geometric_Transform.ppt

Affine Transformations

• Perceptually, Affine Transformations are linear combinations of – Translation – Rotation– Scaling

26

Page 27: CV_Lec10_Geometric_Transform.ppt

Linear Transformations

y

x

y

x*

cossin

sincos

yx, yx ,

x

y

0

• Rotation

27

Page 28: CV_Lec10_Geometric_Transform.ppt

Linear Transformations

ys

xs

y

x

s

s

y

x

y

x

y

x*

0

0

x

y

0

• Scaling

28

Page 29: CV_Lec10_Geometric_Transform.ppt

Linear Transformations

• Reflectionalong X-axis

y

x

y

x

y

x*

10

01

x

y

0

29

Page 30: CV_Lec10_Geometric_Transform.ppt

Linear Transformations

• Reflection along Y-axis

y

x

y

x

y

x*

10

01

x

y

0

30

Page 31: CV_Lec10_Geometric_Transform.ppt

Linear Transformations

• Shearing along X-axis

y

dyx

y

xd

y

x

10

1

x

y

0

31

Page 32: CV_Lec10_Geometric_Transform.ppt

Linear Transformations

• Shearing along Y-axis

dxy

x

y

x

dy

x

1

01

x

y

0

32

Page 33: CV_Lec10_Geometric_Transform.ppt

Affine Transformations• Rotation

1

*

100

0cossin

0sincos

1

y

x

y

x

yx, yx ,

x

y

0

33

Page 34: CV_Lec10_Geometric_Transform.ppt

Affine Transformations

• Scaling

11

*

100

00

00

1

ys

xs

y

x

s

s

y

x

y

x

y

x

x

y

0

34

Page 35: CV_Lec10_Geometric_Transform.ppt

Affine Transformations• Shearing

11

*

100

010

01

1

y

dyx

y

xd

y

x

x

y

0

35

Page 36: CV_Lec10_Geometric_Transform.ppt

Affine Transformations

• Reflection

11

*

100

010

001

1

y

x

y

x

y

x

x

y

0

36

Page 37: CV_Lec10_Geometric_Transform.ppt

Affine Transformations

• Translation

11

*

100

10

01

1y

x

y

x

ty

tx

y

x

t

t

y

x

x

y

0

37

Page 38: CV_Lec10_Geometric_Transform.ppt

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

Page 39: CV_Lec10_Geometric_Transform.ppt

Textbook Page 286Table 6.1

Summary

39

Page 40: CV_Lec10_Geometric_Transform.ppt

Projective Transformations

40

Page 41: CV_Lec10_Geometric_Transform.ppt

Vanishing Point

Vanishing Point Horizon

Line

41

Page 42: CV_Lec10_Geometric_Transform.ppt

Matlab Implementation

• Transformation Techniques– Affine Transformations– Projective Transformations

• Matlab Implementation– function maketform– function imtransform

42

Page 43: CV_Lec10_Geometric_Transform.ppt

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

Page 44: CV_Lec10_Geometric_Transform.ppt

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

Page 45: CV_Lec10_Geometric_Transform.ppt

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

Page 46: CV_Lec10_Geometric_Transform.ppt

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

Page 47: CV_Lec10_Geometric_Transform.ppt

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

47

Page 48: CV_Lec10_Geometric_Transform.ppt

Im = imread('cameraman.tif');figure, imshow(Im), axis on;title(‘Fig.1. Original Gray Scale Image');

axis on

48

Page 49: CV_Lec10_Geometric_Transform.ppt

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

Page 50: CV_Lec10_Geometric_Transform.ppt

Matlab for Scaling

50

Page 51: CV_Lec10_Geometric_Transform.ppt

Scaling

51

Page 52: CV_Lec10_Geometric_Transform.ppt

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

Page 53: CV_Lec10_Geometric_Transform.ppt

Matlab for Rotation

53

Page 54: CV_Lec10_Geometric_Transform.ppt

Rotation

54

Page 55: CV_Lec10_Geometric_Transform.ppt

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

Page 56: CV_Lec10_Geometric_Transform.ppt

Matlab for Shearing

56

Page 57: CV_Lec10_Geometric_Transform.ppt

Matlab for Shearing

57

Page 58: CV_Lec10_Geometric_Transform.ppt

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

Page 59: CV_Lec10_Geometric_Transform.ppt

Matlab for Projection

59

Page 60: CV_Lec10_Geometric_Transform.ppt

Projection

60

Page 61: CV_Lec10_Geometric_Transform.ppt

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

Page 62: CV_Lec10_Geometric_Transform.ppt

Result

62

Page 63: CV_Lec10_Geometric_Transform.ppt

Textbook Page 309Table 6.2

63

Page 64: CV_Lec10_Geometric_Transform.ppt

Textbook Page 316Table 6.3

64

Page 65: CV_Lec10_Geometric_Transform.ppt

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

Page 66: CV_Lec10_Geometric_Transform.ppt

Take Home Message

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

66