Click here to load reader
Upload
isma807
View
437
Download
0
Embed Size (px)
DESCRIPTION
MATLAB IMAGE RESTORATION
Citation preview
12/18/13 Find Image Rotation and Scale - MATLAB & Simulink Example
www.mathworks.com/help/images/examples/find-image-rotation-and-scale.html 1/3
Find Image Rotation and Scale
This example show s how to align or register tw o images that differ by a rotation and a scale change. You can use fitgeotrans
to f ind the rotation angle and scale factor after manually picking corresponding points. You can then transform the distorted image
to recover the original image.
Step 1: Read Image
Read an image into the w orkspace.
original = imread('cameraman.tif');
imshow(original);
text(size(original,2),size(original,1)+15, ...
'Image courtesy of Massachusetts Institute of Technology', ...
'FontSize',7,'HorizontalAlignment','right');
Step 2: Resize and Rotate the Image
scale = 0.7;
distorted = imresize(original,scale); % Try varying the scale factor.
theta = 30;
distorted = imrotate(distorted,theta); % Try varying the angle, theta.
figure, imshow(distorted)
12/18/13 Find Image Rotation and Scale - MATLAB & Simulink Example
www.mathworks.com/help/images/examples/find-image-rotation-and-scale.html 2/3
Step 3: Select Control Points
Use the Control Point Selection Tool to pick at least tw o pairs of control points.
movingPoints = [151.52 164.79; 131.40 79.04];
fixedPoints = [135.26 200.15; 170.30 79.30];
You can run the rest of the example w ith these pre-picked points, but try picking your ow n points to see how the results vary.
cpselect(distorted,original,movingPoints,fixedPoints);
Save control points by choosing the File menu, then the Save Points to Workspace option. Save the points, overw riting
variables movingPoints and fixedPoints.
Step 4: Estimate Transformation
Fit a nonreflective similarity transformation to your control points.
tform = fitgeotrans(movingPoints,fixedPoints,'nonreflectivesimilarity');
After you have done Steps 5 and 6, repeat Steps 4 through 6 but try using 'aff ine' instead of 'NonreflectiveSimilarity'. What
happens? Are the results as good as they w ere w ith 'NonreflectiveSimilarity'?
Step 5: Solve for Scale and Angle
The geometric transformation, tform, contains a transformation matrix in tform.T. Since you know that the transformation
includes only rotation and scaling, the math is relatively simple to recover the scale and angle.
Let sc = s*cos(theta)
Let ss = s*sin(theta)
Then, Tinv = invert(tform), and Tinv.T = [sc -ss 0;
ss sc 0;
tx ty 1]
where tx and ty are x and y translations, respectively.
tformInv = invert(tform);
Tinv = tformInv.T;
ss = Tinv(2,1);
12/18/13 Find Image Rotation and Scale - MATLAB & Simulink Example
www.mathworks.com/help/images/examples/find-image-rotation-and-scale.html 3/3
sc = Tinv(1,1);
scale_recovered = sqrt(ss*ss + sc*sc)
theta_recovered = atan2(ss,sc)*180/pi
scale_recovered =
0.7000
theta_recovered =
29.3741
The recovered values of scale_recovered and theta_recovered should match the values you set in Step 2: Resize and
Rotate the Image.
Step 6: Recover Original Image
Recover the original image by transforming distorted, the rotated-and-scaled image, using the geometric transformation tform
and w hat you know about the spatial referencing of original. The 'OutputView ' Name/Value pair is used to specify the
resolution and grid size of the resampled output image.
Roriginal = imref2d(size(original));
recovered = imwarp(distorted,tform,'OutputView',Roriginal);
Compare recovered to original by looking at them side-by-side in a montage.
figure, imshowpair(original,recovered,'montage')
The recovered (right) image quality does not match the original (left) image because of the distortion and recovery process.
In particular, the image shrinking causes loss of information. The artifacts around the edges are due to the limited accuracy of the
transformation. If you w ere to pick more points in Step 3: Select Control Points, the transformation w ould be more accurate.