10

I am trying to find circles in images and warp them back to a canonical view (i.e. as if looking into the center). However, circles in general project to ellipses under perspective transformations. So I am first detecting ellipses, roughly doing the following (in OpenCV):

1. Find contours in the image
2. Estimate area of contour
3. Fitting a bounded box to contour and estimating area by width/2 * height/2 * PI (area of ellipse)
4. checking if area of contour and estimated area of ellipse is < a threhsold

Assuming I have found an ellipse by this method, how can I rectify it back to a circle such that I "undo" the perspective transform (although not in plane rotation as this cannot be done I guess). For example, if it was a rectangle I would just compute the homography from the 4 corners of an uprigh rectangle to the detected projected one.

I have no idea how to do this with an ellipse, any help is much appreciated.

Thanks

Aly
  • 15,865
  • 47
  • 119
  • 191
  • You could assume the boundin rectangle around the ellipse (width/height are common ellipse parameters anyway) and project it to a square?!? – Micka Oct 04 '14 at 10:17
  • 2
    @Micka You would have to detect a more complex bounding quadrilateral than a rectangle, since a square is not deformed into a rectangle under a general perspective transformation. – BConic Oct 04 '14 at 17:28

2 Answers2

7

A circle is indeed transformed into an ellipse by a perspective transformation, however its axes are not the same as the axes of the initial circle, as shown in this illustration:

Ellipse vs Perspective circle
(source: brian-curtis.com)

You can refer to this link for a detailled demonstration. As a consequence, the bounding rectangle of the ellipse is not the image of the initial square by the perspective tranformation.

EDIT:

This means that the center and the axes of the ellipse you observe are not the images, by the perspective mapping, of the center and axes of the original circle. I tried to make a clearer illustration:

enter image description here

On this image, I drew in green the axes and center of the original circle, after perspective transformation, and the axes and center of the ellipse in red. On this specific example, the vertical axis is not deformed by the perspective mapping, but it would be deformed in the general case. Hence, deforming a circle by a perspective transformation gives an ellipse, but the axes and center that you see are not the axes and center of the original circle.

As a consequence, you cannot simply use the top, bottom, left and right points on the ellipse (the red points, which can easily be detected from the ellipse) to map these onto the top, bottom, left and right points of the circle because they do not correspond under the perspective mapping (the green points do, but they cannot be detected easily from the ellipse).

In the end, I don't think that it is at all possible to estimate the perspective mapping from a single detected ellipse.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
BConic
  • 8,750
  • 2
  • 29
  • 55
  • Could I not just find the top, bottom, left and right points on the ellipse (given by the width and height from the center) and map these on to the top, bottom, left, right of a circle of radius r. And find the homography this way? Of course this may not be correct to in plane rotation, but then one can simply rotate the warped ellipse by 90 degrees in plane – Aly Oct 04 '14 at 23:18
  • @Aly See the edit of my answer. A little more details on what you want to do would be useful to find a work-around. Maybe you can draw a cross within the circle to be detected in order to mark its true center for easier detection? – BConic Oct 05 '14 at 08:10
  • @Aly Also, depending on the accuracy you require, it might be enough to approximate the true axes and center of the circle with the axes and center of the observed ellipse. – BConic Oct 05 '14 at 08:26
  • Nice answer. If you add some more samples you can show that the foreshortened circle image is ambiguous. I ask myself whether the bounding trapez will always have base lines parallel to flat ellipse's axis? – Micka Oct 05 '14 at 20:24
6

This looks like an indeterminate problem.

The projection of a rectangle supplies 8 equations in 8 unknowns (homography coefficients).

With an ellipse, you can only retrieve the center coordinates (2 DOF), the axis (2 DOF) and the axis orientation (1 DOF).