# find the rotation of one image with respect to other in MATLAB

I have two images. One is the reference image and the other is the rotated version of the reference image. I would like to find what is the angle by which the second image is rotated with respect to the first one. i want this to work automatic.

-

You can look at optical flow, OpenCV has a function that provides this functionality.

http://tech.groups.yahoo.com/group/OpenCV/message/67973

Optical flow returns points that are similar between two successive frames, which can be used to calculate a rotation. This function will work best on twoframes that are not too different from eachother. I am not sure how big a rotation we are talking about here, if it is too high, optflow might not be the best option.

As mentioned in the link above, using SIFT might a better option. SIFT calculates features that can be used to match objects, corners from different angles, even with occulusions (so you only see part of the object, but SIFT numbers can still match), in that case, if there are enough SIFT matches between two features, these can be used to calculate a rotation.

-
Enumerate over all possible angles (under some reasonable discretization), rotate one of the images, and calculate the $L_2$ distance (sum of squared differences); the angle at which the distance is minimal is the one you seek.
go over all possible angles, up to some discretization, i.e. $2\pi n/N$ for $n=0,\ldots,N-1$ and $N$ is "big enough". –  Yuval Filmus Dec 22 '10 at 20:42