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

我们两清 提交于 2019-12-24 01:25:09

问题


I would like to :

  • step 1) Rotate an image with 20 degrees using this code rotatedImage = imrotate(originalImage, 20);.

  • step 2) calculate degree rotation used in step 1 based only on the rotated image if it possible or based on rotated image and the original image.

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


回答1:


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

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.




回答2:


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



来源:https://stackoverflow.com/questions/18703995/how-to-know-rotation-degree-in-matlab-for-a-rotated-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!