I have a 2D binary image containing a single object, and I'm trying to determine the largest ellipse that fits entirely within that object.

There are many techniques that will quickly fit an ellipse in a best-fit sense to the object, but this does not ensure that the ellipse will be entirely within the bounds of the object - in fact, unless the object is a perfect ellipse, they usually guarantee that it won't.

I have tried using a cost function and search algorithms to refine a starting estimate, but this is too slow. I've been using a home-made iterative technique, where I erode away edges, but this is also slow. I'm starting to wonder if I'm reinventing the wheel here.

[Edit] ----------------------------------------------------------------------------------------------

Thanks all for your replies. I'm adding some more detail.

Here is a link to some artificial data: http://img211.imageshack.us/img211/223/ellipseresult.png

I hope this works; I can't check it at work, I have to wait until I get home. The aritificial data shows a white region with a green ellipse "fitted" to it in the manner I discussed above. I can't provide "real" data unfortunately, but the artificial is a pretty good likeness.

To clarify, by largest ellipse, I mean the largest area (unfortunately - axis would be easy!). As to the issue of speed, I should probably add that I am trying to get this done very quickly, because it needs to be done for hundreds (if not thousands) of ellipses, so anything that takes a few seconds is not considered fast in this context. I think the operator would expect the result in a minute or two, maximum, for about a thousand ellipses. Having said that, if it can't be done, it can't be done.

I have tried a combination of estimation and then refine with a cost function and search algorithm. This seems too slow given the number of ellipses, as I discussed above. The other method I tried was an iterative approach which started with a list of boundary points, then discarded those that seemed to be too far "outside" for a fit. The next step is to fit the points which are either ont he ellipse or inside the ellipse, in an iterative fashion. I think this is what Jeffrey was also suggesting in the first part of his answer (encouraging if someone else is thinking on the same lines).

Technically, all of the ellipse should be inside the object. An error margin of about 0.5 pixels seems appropriate though to accomodate interpolation and thresholding.

I am going to try further refining my iterative solution. I will try being more ruthless in the early stages of pruning boundary points, and I will look for a faster algorithm for ellipse estimation. I'm currently implementing this in MatLab, and I'm using someone's implementation of the Trusted Region algorithm (I'd put in the name, but I can't get to the MatLab site right now). Eventially, I may switch it from MatLab to something like OpenCV to see how much speed gains I can get. Unfortunately, this will first mean learning OpenCV!

Similar questions and discussions