user1847831
user1847831

Reputation: 65

How to know rotation degree in matlab for a rotated image?

I would like to :

there is any function in matlab could do the step 2 or a proposition to do that?

Upvotes: 2

Views: 1790

Answers (2)

Autonomous
Autonomous

Reputation: 9075

You might want to check this. I had used Fourier-Mellin transform to retrieve rotation. Its accurate up to 1 degree. I think you will have to invest some time + don't forget to check some papers on Fourier-Mellin transform

Upvotes: 2

Buck Thorn
Buck Thorn

Reputation: 5073

This example shows one way to perform step 2:

A = 'peppers.jpg';
img = im2double(imread(A));
img_r=imrotate(img,20,'nearest','crop');   % <-- this is the distorted image
                                           %     rotated 20 deg

xopt = fminsearch(@(x) imr(x,img_r,img), 10);  % <-- start with 10 deg as guess

where imr is the function

function obj= imr(x,img1,img2);
img1_r = imrotate(img1,x,'nearest','crop');
obj = sum((img2(:)-img1_r(:)).^2);

The function wraps imrotate, generating an objective function to minimize so that it can be used by fminsearch.

This shows the original, distorted, and reversed image (with angle determined as above):

enter image description here

Note the limitations: the rotated images are cropped so that a point-by-point comparison is possible during computation of the objective function. This is probably not the absolutely best way to do this, as I imagine that there are morphological algorithms designed to answer your specific question in a more general way. Still it worked.

Upvotes: 5

Related Questions