how to find the right distance evaluation function of an ellipse

I want to fit a 2D data set to an ellipse using the ransac algorithm . Therefore I use the an equation in polar coordinates, with the origin at the center of the ellipse and with the angular coordinate theta.
ft = fittype( @(a,b,theta,r) (a*b)./sqrt((b*cos(theta)).^2+(a*sin(theta)).^2), 'independent', 'theta', 'dependent','r', 'coefficients', {'a','b'});
fitLineFcn = @(points) fit(points(:,1),points(:,2),ft ) % type function handle
evalLineFcn = ... % distance evaluation function
[modelRANSAC, inlierIdx] = ransac(points,fitLineFcn,evalLineFcn, sampleSize,maxDistance);
How can I compute distances from an ellipse to the data. The example doesnt help me at all.

Risposte (1)

6 Commenti

I understand your method, but you are using the ellipse equation matrix.
I can't use your equation ellipsefun=@(p,q) sum([p;q].*(A*[p;q]))-1 ;
because I need a function handle. I can write an anonymous function that simply evaluates the fit, like f = @(x) F_fitted(x), but my data set is given in polar coordinates.
My problem is, I cant compare my data set to my fit, because I cant compute distances from my ellipse to the data set. Do you have any idea how I can fix this?
Thank you in advance !
Here is my incomplete code:
sampleSize = 5; % number of points to sample per trial.
maxDistance = 2; % max allowable distance for inliers
data_polar = [magnitude angle];
fitellipsefnc = @(angle, magnitude) Ellipse_fitted(angle , magnitude);
distfnc = ??????
[modelRANSAC,inlierIdx] = ransac(data_polar,fitellipsefnc,distfnc,sampleSize,maxDistance);
function fit_ransac = Ellipse_fitted(angle, magnitude)
ft = fittype( @(a,b,theta,r) (a*b)./sqrt((b*cos(theta)).^2+(a*sin(theta)).^2), 'independent', 'theta', 'dependent','r', 'coefficients', {'a','b'});
fit_ransac = fit(angle, magnitude, ft);
end
My problem is, I cant compare my data set to my fit, because I cant compute distances from my ellipse to the data set. Do you have any idea how I can fix this?
The link I gave you showed how to calculate the distance of an arbitrary point y (in Cartesian coordinates) to the ellipse, using trustregprob() from the File Exchange.
Aroot=chol(A);
L=Aroot\eye(2);
z=Aroot\trustregprob(L.'*L, L.'*y,1); %closest point on ellipse
distance=norm(z-y)
but my data set i given in polar coordinates.
You can use pol2cart() to convert them to Cartesian coordinates.
How can I get your matrix ellipse equation in my fit() ?
You told me last month that I need my ellipse as an explicit function.
How can i combine your approach uncluding the ellipse equation matrix and the explicit function ?
Incomplete code does us no good. For example it hits an error when it needs magnitude and angle. You keep forgetting to attach your data. Why???
You keep forgetting to attach your data. Why???
Why do you need my data ?? My problem is to combine an explicit function and the ellipse equation matrix. There is no data needed.
How can I get your matrix ellipse equation in my fit() ?
Once you have fitted the ellipse, you have the major and minor axes lengths a and b. Assuming you convert your data to a cartesian coordinate system in which the major axis is the x-axis, the A matrix will be given by
A=[1./a.^2, 0;0 1./b.^2];

Accedi per commentare.

Prodotti

Release

R2020a

Richiesto:

il 25 Set 2020

Commentato:

il 29 Set 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by