260 likes | 297 Views
Digital Image Processing & Pattern Analysis (CSCE 563) Geometric Transformations. Prof. Amr Goneid. Department of Computer Science & Engineering The American University in Cairo. Geometric Transformations. Image Cropping Interpolation Image Resizing Image Rotation Affine Transform
E N D
Digital Image Processing&Pattern Analysis (CSCE 563) Geometric Transformations Prof. Amr Goneid Department of Computer Science & Engineering The American University in Cairo
Geometric Transformations • Image Cropping • Interpolation • Image Resizing • Image Rotation • Affine Transform • Image Registration Prof. Amr Goneid, AUC
Image Cropping • Cropping refers to the removal of the outer parts of an image to select a rectangular ROI. • In MATLAB, The bounding rectangle is rect = [col,row,w,h] • B = imcrop or [B , rect] = imcrop; uses mouse to define area • B = imcrop(A,rect); Returns the cropped image defined by the bounding rectangle A B h w col,row Prof. Amr Goneid, AUC
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
Interpolation • 2-D Interpolation • Used in resizing and rotation • Nearest Neighbor Interpolation (nearest) • Bilinear Interpolation (bilinear) • Bicubic Interpolation (bicubic) Prof. Amr Goneid, AUC
Interpolations Nearest Neighbor Bilinear Prof. Amr Goneid, AUC
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 fat 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
Example:Bilinear interpolation • Linear interpolation in the x-direction • interpolating in the y-direction • This yields Prof. Amr Goneid, AUC
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
Resizing using Interpolation No Interpolation Resize by 183% Original With Interpolation Prof. Amr Goneid, AUC
Resizing • B = 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
Rotation • B = imrotate(A,angle); or B = 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
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
Affine Transform Prof. Amr Goneid, AUC
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. Prof. Amr Goneid, AUC
Affine Transform Prof. Amr Goneid, AUC
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
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
Affine Transform Prof. Amr Goneid, AUC
Affine Transform Prof. Amr Goneid, AUC
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
Image Registration CP CP Prof. Amr Goneid, AUC
Image Registration CP CP CP CP Prof. Amr Goneid, AUC
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