Ellipse fitting similar to ImageJ feature

asked 2019-10-05 07:17:25 -0500

updated 2019-10-06 05:30:30 -0500

I have captured images from a video camera and have performed some thresholding so I can detect edges. In ImageJ I can successfully select the inner circle of a donut shaped object with the wand tool, and then use the selection ellipse fit feature to select the inner ellipse and then use the measure feature to get the major/minor/orientation attributes of the ellipse.

Now I want to be able to perform the same functions in Python (using opencv, numpy, scipy, PIL, ...).

Does anyone know how to do this or suggest where to look/ask?

My main stumbling block is finding an equivalent of the ellipse points that the ImageJ wand tool does.


What I've tried is the Ellipse Hough Transform referenced here.


The article looks like it would be a perfect fit for what I am trying to achieve, however,

(a) it works on the sample image ok, but it takes a long time (many seconds). I would prefer something that is sub-second to get some kind of real-time performace.

(b) it doesn't seem to work at all on my images. The code just seems to "hang" and never return from the call to hough_ellipse()

With ImageJ if I select the wand tool, click in the inner ellsipse or on its edge, the yellow highlighted circule appears instantaneously.

I then click on the "Analyze > Measure" menu item to get the measurements (shows area, major, minor, angle attributes) and the results are instantaneous.

Actually there is another step => select menu "Edit > Selection > Fit Ellipse", then do the Measure function. Either way pre or post ellipse fit, the results are very similar.

I want to achieve the same with Python, preferably with opencv, but am open to other libraries too. I assume that selecting outlines of shapes/contours etc is quite common image processing for graphical apps and even computer vision, and some helpful functions are likely available in a library somewhere.

At the end of the day I want to get a reasonably accurate measuremnt of major and minor ellipse attributes, so I need to be able to automatically select/detect an ellipse and run it through an algorithm to determine major/minor.



image description

image description

image description

edit retag flag offensive close merge delete



can you show, what you tried so far ? also, an example image ?

berak gravatar imageberak ( 2019-10-05 09:47:17 -0500 )edit

I've updated the question above with more details (what I've tried and images, etc). Thanks, Brendan.

Brendan Simon gravatar imageBrendan Simon ( 2019-10-06 05:28:46 -0500 )edit

I would try something like:

  • Canny > findContours > use mouse cursor position + pointPolygonTest to get the correspond contour > fitEllipse
Eduardo gravatar imageEduardo ( 2019-10-06 07:03:53 -0500 )edit