image fit

I have a binary image that shows a black spot (binary value 0) on a white background (binary value 255) and a bit of noise (if a binary image can be noisy). See attached png. I want to fit this image to an ellipse like with the following formula:
w[0]*(x-w[3])^2 + w[1]*(y-w[4])^2 +2*w[2]*(x-w[3])*(y-w[4]) - 1 < 0 ? 0 : 255
where w is also the coefficient wave to be optimized by the fit. The attached png shows also a contour plot whose 2D wave is calculated with the above formula and the coefficients w[0]= {0.0019,0.0025,-0.00015,25,23}. It meets the original image quite good, but it is nevertheless a manual fit and I want to use Igor's fitting routines.
Does anybody know how to start here or even have a better approach?

Andreas Wirsing
Wow. That's a tough one.

I don't think you can use ordinary curve fitting because you're not fitting values.

I think you might be able to use Optimize if you can come up with a suitable merit function that has a maximum or minimum when the ellipse coefficients are optimum. Maybe something along the lines of a penalty function that sums the number of pixels that are in the wrong region- that is, white pixels inside the ellipse and black pixels outside it both increment the merit (or I guess in this case, penalty) function.

I foresee difficulties, though, because the values are rough- the penalty function will change value abruptly as each pixel is added or removed. That kind of function is difficult for ordinary optimizers.

You might refine the function by adding fractional pixels for the pixels that fall on top of the ellipse- add just the fraction of the pixel that is on the wrong side of the ellipse. That would make the function smoother.

There is probably a better technique, but I don't know what it is :)

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Could you use an image processing method to pull out only the points at the boundary and then fit them to an ellipse function?

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
Hello Andreas,

The built-in ImageAnalyzeParticles provides a method for computing the fitting ellipse. The various moments are calculated by the operation and the fitting ellipse is computed by the WMImageDoPartEllipse() procedure in the file: WaveMetrics Procedures:Image Processing:Image Particle Panel.ipf.

I hope this helps,

A.G.
WaveMetrics, Inc.
Igor wrote:
The built-in ImageAnalyzeParticles provides a method for computing the fitting ellipse. The various moments are calculated by the operation and the fitting ellipse is computed by the WMImageDoPartEllipse() procedure in the file: WaveMetrics Procedures:Image Processing:Image Particle Panel.ipf.


This was exactly, what I was looking for. Thanks a lot.

Andreas