cv_lec10_geometric_transform.ppt

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

Upload: mujeeb-abdullah

Post on 29-Nov-2015

4 views

Category:

Documents


0 download

DESCRIPTION

Geometric

TRANSCRIPT

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

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 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

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

Center13

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

17

Rotation

x’ -5 -3 -3

y’ 1 1 2

x -3 -3 -2

y 3 1 1

x

y

0

theta = 90o

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 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

Linear Transformations

y

x

y

x*

cossin

sincos

yx, yx ,

x

y

0

• Rotation

27

Linear Transformations

ys

xs

y

x

s

s

y

x

y

x

y

x*

0

0

x

y

0

• Scaling

28

Linear Transformations

• Reflectionalong X-axis

y

x

y

x

y

x*

10

01

x

y

0

29

Linear Transformations

• Reflection along Y-axis

y

x

y

x

y

x*

10

01

x

y

0

30

Linear Transformations

• Shearing along X-axis

y

dyx

y

xd

y

x

10

1

x

y

0

31

Linear Transformations

• Shearing along Y-axis

dxy

x

y

x

dy

x

1

01

x

y

0

32

Affine Transformations• Rotation

1

*

100

0cossin

0sincos

1

y

x

y

x

yx, yx ,

x

y

0

33

Affine Transformations

• Scaling

11

*

100

00

00

1

ys

xs

y

x

s

s

y

x

y

x

y

x

x

y

0

34

Affine Transformations• Shearing

11

*

100

010

01

1

y

dyx

y

xd

y

x

x

y

0

35

Affine Transformations

• Reflection

11

*

100

010

001

1

y

x

y

x

y

x

x

y

0

36

Affine Transformations

• Translation

11

*

100

10

01

1y

x

y

x

ty

tx

y

x

t

t

y

x

x

y

0

37

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

Textbook Page 286Table 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, 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 Scaling

50

Scaling

51

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 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 309Table 6.2

63

Textbook Page 316Table 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

*

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