find the rotation of one image with respect to other
I have 2 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 2nd image is rotated wrt 1st on开发者_开发百科e.i want to do this automatically.
Brute-force it! Write a function to compare the intersection of the rotated images (sum of the difference or sum of the difference squared between each point), and then iterate through rotation angles to find the one corresponding to the minimum difference.
Although knowing matlab there's probably a function that just tells you the rotation, but it's called something weird.
The general method for doing this is:
Use an algorithm such as SIFT to get a list of interest-point descriptors. These descriptors provide scale, direction and geometry of the interest points. The geometry information is scale- and rotation-invariant.
Use a nearest-neighbor algorithm to match interest points in each of the pictures by comparing geometries.
for each pair of matching interest points, compare their scale and rotation.
Ideally, all of the matching interest points will have the same relative scale and rotation. However, variability in how the pictures were taken and inaccuracy in the previous stages will introduce variable scales and rotations, so:
- use an algorithm such as RANSAC to determine the best-fitting scale and rotation.
QED
NOTE: Since the question did not originally ask for an automated solution, I had posted this solution which requires a set of control points to be selected by the user for each image. Although the requirements in the question have been updated, I think this answer could still be useful for anyone wanting to do image registration in MATLAB, so I'm leaving it here...
The non-automated approach:
What you're asking about is known as image registration, and one option you have is to use the function CP2TFORM from the Image Processing Toolbox.
In fact, there's a very nice example in that function's documentation which looks like it tackles the same exact problem you're trying to solve.
Here is an example of how to recover a transformation between two images using local features and RANSAC from the Computer Vision System Toolbox.
Here is the code.
http://www.mathworks.com/matlabcentral/fileexchange/1713-three-dimensional-reconstruction-from-planar-slices
This algorithm use apriori knowledge that the two objects are round. YMMV
精彩评论