Digital Image Processing & Pattern Analysis (CSCE 563) Geometric Transformations Prof. Amr Goneid...

Post on 14-Jan-2016

217 views 0 download

Transcript of Digital Image Processing & Pattern Analysis (CSCE 563) Geometric Transformations Prof. Amr Goneid...

Digital Image Processing&

Pattern Analysis (CSCE 563)

Geometric Transformations

Digital Image Processing&

Pattern Analysis (CSCE 563)

Geometric Transformations

Prof. Amr Goneid

Department of Computer Science & EngineeringThe American University in Cairo

Prof. Amr Goneid, AUC 2

Geometric TransformationsGeometric Transformations

Image Cropping

Interpolation

Image Resizing

Image Rotation

Affine Transform

Image Registration

Prof. Amr Goneid, AUC 3

Image CroppingCropping refers to the removal of the outer parts of an image to select a rectangular ROI.In MATLAB, The bounding rectangle isrect = [col,row,w,h]B = imcrop or[B , rect] = imcrop;uses mouse to define areaB = imcrop(A,rect);Returns the cropped image definedby the bounding rectangle

Bh

w

col,row

A

Prof. Amr Goneid, AUC 4

Example: Top Left Quadrant

load treesc;

[n,m] = size(X);

rect = [1,1,m/2,n/2];

B = imcrop(X,rect);

subplot(2,1,1);

imshow(X,map);

subplot(2,1,2);

imshow(B,map);

Prof. Amr Goneid, AUC 5

Interpolation

2-D Interpolation

Used in resizing and rotation

Nearest Neighbor Interpolation (nearest)

Bilinear Interpolation (bilinear)

Bicubic Interpolation (bicubic)

Prof. Amr Goneid, AUC 6

Interpolations

Nearest Neighbor Bilinear

Prof. Amr Goneid, AUC 7

Example:Bilinear interpolation(From Wikipedia)

bilinear interpolation is an extension of linear interpolation for interpolating functions of two variables on a regular grid.

The key idea is to perform linear interpolation first in one direction, and then again in the other direction.

to find the value of the unknown function f at the point P = (x, y). It is assumed that we know the

value of f at the four points

Q11 = (x1, y1), Q12 = (x1, y2),

Q21 = (x2, y1), and Q22 = (x2, y2).

Prof. Amr Goneid, AUC 8

Example:Bilinear interpolation

Linear interpolation in the x-direction

interpolating in the y-direction

This yields

Bilinear interpolation

In a coordinate system in which the four points are at (0, 0), (0, 1), (1, 0), and (1, 1), then in matrix form

The result of bilinear interpolation is independent of the order of interpolation. If we had first performed the linear interpolation in the y-direction and then in the x-direction, the resulting approximation would be the same.

Prof. Amr Goneid, AUC 9

Prof. Amr Goneid, AUC 10

Resizing using Interpolation

Resize by 183%

Original

No Interpolation

With Interpolation

Prof. Amr Goneid, AUC 11

ResizingB = imresize(A,m,’method’)

m = ratio

Example:

load clownc;

B = imresize(X,3,’nearest’);

C = imresize(X,0.3,’nearest’);

subplot(3,1,1); imshow(X,map);

subplot(3,1,2); imshow(B,map);

subplot(3,1,3); imshow(C,map);

Prof. Amr Goneid, AUC 12

RotationB = imrotate(A,angle); orB = imrotate(A,angle,’crop’);angle is anti-clockwise (degrees)Example:load amber256;C = imrotate(X,45,'crop');subplot(2,1,1);imshow(X,map);subplot(2,1,2);imshow(C,map);

Prof. Amr Goneid, AUC 13

Affine Transform

Let f be an image defined over (w,z) coordinate system, g is a geometric transformation of f with:

(x , y) = T{(w , z)}

Example:

(x , y) = T{(w , z)} = (w/2 , z/2)

This is shrinking f by ½ in both spatial dimensions.

Prof. Amr Goneid, AUC 14

Affine Transform

Prof. Amr Goneid, AUC 15

Affine Transform

Commonly used transform is the Affine Transform, in matrix form:

[x y 1] = [w z 1] T = [w z 1]

Can produce scaling, translation, rotation and shear.

1

0

0

3231

2221

1211

tt

tt

tt

Prof. Amr Goneid, AUC 16

Affine Transform

Prof. Amr Goneid, AUC 17

Affine Transform

MATLAB Example (scaling):

T = [2 0 0; 0 3 0; 0 0 1];

tform = maketform(‘affine’ , T);

wz = [1 1; 3 2];

xy = tformfwd(wz , tform);

Result is xy = [2 3; 6 6];

Also:

wz2 = tforminv(xy , tform); % inverse transform

Prof. Amr Goneid, AUC 18

Affine Transform

Examples:

• Scale Horizontally by 3 and vertically by 2

T1 = [3 0 0; 0 2 0; 0 0 1];

• Shear

T2 = [1 0 0; 0.2 1 0; 0 0 1];

• Tscale = [1.5 0 0; 0 2 0; 0 0 1];

Trot = [cos(pi/4) sin(pi/4) 0; -sin(pi/4) cos(pi/4) 0; 0 0 1];

Tshear = [1 0 0; 0.2 1 0; 0 0 1];

T3 = Tscale * Trot * Tshear;

Prof. Amr Goneid, AUC 19

Affine Transform

Affine Transform

Prof. Amr Goneid, AUC 20

Image Registration

Image registration is the process of overlaying two or more images of the same scene taken at different times, from different viewpoints, and/or by different sensors.

Applications: Change detection, Image fusion, Target recognition, Target localization, Depth perception, Image mosaicing, Motion estimation

Prof. Amr Goneid, AUC 21

Image Registration

Prof. Amr Goneid, AUC 22

CP

CP

Image Registration

Prof. Amr Goneid, AUC 23

CP

CP

CP

CP

Image Registration (References)

• Image registration methods: a survey

Barbara Zitova´*, Jan Flusser

http://library.utia.cas.cz/prace/20030125.pdf• Image Registration

http://tango.andrew.cmu.edu/~gustavor/42431-intro-bioimaging/readings/ch8.pdf

• Image Registration in MATLAB

http://www.mathworks.com/help/toolbox/images/f20-9579.html

Prof. Amr Goneid, AUC 24