Path: news.mathworks.com!not-for-mail
From: "Luca " <l.presottoRE@MOVE.campus.unimib.NOTit>
Newsgroups: comp.soft-sys.matlab
Subject: Fitting an ellipse to an image
Date: Tue, 12 Jun 2012 14:57:07 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 15
Message-ID: <jr7lc3$akh$1@newscl01ah.mathworks.com>
Reply-To: "Luca " <l.presottoRE@MOVE.campus.unimib.NOTit>
NNTP-Posting-Host: www-04-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1339513027 10897 172.30.248.35 (12 Jun 2012 14:57:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 12 Jun 2012 14:57:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2218739
Xref: news.mathworks.com comp.soft-sys.matlab:770884

I have the following problem. I have an image where there is an object that looks very much like half an ellipsoidal annulus in an uniform background.
It is very clear and sharp.
Therefore I want to fit an ellipsoidal annulus to it. 
Seems an easy task. 
I'm working in 3D therefore I have 11 parameters to describe this object: center coordinate (p1,p2,p3), short axis(p4), long axis (p5), thickness of the annulus (p6), description of the plane cutting in half the ellipsoidal annulus (p7,p8,p9), mean value of the background (p10), mean value of the ellipsoidal annulus (p11).

First thing I've tried: do an intensity segmentation, get a map of 1 and 0 (where there is and where there isn't my annulus), make my ellipsoidal annulus mask, xor the two mask, count the number of 1 in the xor (in this way I had only 9 parameters, not 11, as the last two did not apply). Minimize the difference with fminsearch.
Works great as long as the first segmentation went fine . Which does not always happens. So, to make my code more sensible and to avoid a non-useful step as the first segmentation, I tried to generate a full image of this annulus in the background and then calculate a difference between this image and mine. (I used sum of squared differences).
I tried to minimize this function with fminunc (for what I've been told I shouldn't be using fminsearch already with 9 parameters, go figure with 11) and it does not work. Can't get anywhere. It stops at iteration 1 and says: "can't minimize the function along the current search direction". I investigated and I think that the problem lies in the fact that this objective function has a randomatic behaviour for very small changes in the parameters (for dx=~0.001. amplitude of local minima induced by such dx: ~0.0001*f(x) ). I think this is screwing fminunc up. 
I think that the reason for this is that my annulus is computed as a discrete mask. Therefore a small change in its parameters does not change the whole mask but just a couple of pixels at a time, producing a random and not continous behaviour.
Said that I don't have any idea of how to generate a "less discretized" ellipsoid. Can anybody suggest me anything?

BTW, out of desperation I've tried fminsearch.
It works fine.
Any suggestion on what could I do?