2

I need to find the rotation angle between two binary images. SO I can correct the rotation by rotating the images by the specified angle. Can someone help please? image1

rotated image

I already tried the Principle axis rotation angle but It doesn't give accurate result. Can some one suggest me a better method. And this image an be anything. It need not to be the image I uploaded here. But all the images are binary.

SameeraR
  • 415
  • 1
  • 6
  • 19

2 Answers2

1
  • Threshold source.

  • Apply thinning algorithm as described here.

  • Find contour and approxPolyDP.

  • Now for each consecutive points calculate angle.

    double angle = atan2(p1.y - p2.y, p1.x - p2.x)
    
  • Do the same for second image and calculate difference in angle.

Community
  • 1
  • 1
Haris
  • 13,645
  • 12
  • 90
  • 121
0

For each image

  • Threshold the image so that object pixels are non-zero and background pixels are zero
  • Find the convexhull of the non-zero pixels (you may use any method to reduce the number of points that you use to calculate the convexhull, such as first finding contours. The main idea is to find the convexhull)
  • Calculate the minimum-area-rectangle using minAreaRect and it'll return a RotatedRect object (in C++). This object contains the rotation angle
  • Take the difference

Note: this approach will not work if somehow the resulting min-area-rect returns the same angle though the object rotation is different. Therefore, I feel it's better to use other measures such as moments of the filled convexhull to calculate the rotation: http://en.wikipedia.org/wiki/Image_moment

dhanushka
  • 10,492
  • 2
  • 37
  • 47