Ellipse implicit equation coefficients

Hi I have a set of 2D points and I want to know the coefficients of the following implicit equation of the ellipse: Ax^2+2Bxy+Cy^2=1
Any idea?
Moreover, I have found the best fitting ellipse with its major, minor axes, center and orientation. Can I can use this information to find the above mentioned three coefficients (A,B and C)?
The implementations of ellipse fitting already available in Matlab Central use the general form of ellipse, I do not need coefficients for those.
Best Regards Wajahat

 Akzeptierte Antwort

Richard Brown
Richard Brown am 1 Mai 2012

0 Stimmen

First, if the centre is nonzero, then that form of the ellipse equation will not work. You need the more general quadratic form
(*) x^' * A * x + c' * x + d = 0
where A is a 2x2 symmetric matrix, c a 2x1 vector and d a scalar. Multiplying out gives the full equation
a_11 x^2 + 2a_12 xy + a_22 y^2 + c_1 x + c_2 y + d = 0
If you used my code: http://www.mathworks.com/matlabcentral/fileexchange/15125-fitellipse-m/ then what you get when you fit your ellipse is the centre z, the orientation of the major axis as a counterclockwise rotation from the x-axis alpha , and a and b the semimajor and semiminor axes respectively. Any of the other fitting codes probably return similar parameters.
These correspond to the following parametric equation for the ellipse (parametrised by theta in [0, 2\pi])
x = z + Q * [a * cos(theta); b * sin(theta)]
where
Q = [cos(alpha), -sin(alpha); sin(alpha) cos(alpha)]
All you need to do to get back to the quadratic form is to eliminate theta. First some algebra
diag([1/a, 1/b]) * Q'*(x - z) = [cos(theta); sin(theta)] = u
Using the fact that u'*u = 1,
(x - z)' * Q * diag([1/a^2, 1/b^2]) * Q' * (x - z) = 1
or
(x - z)' * A * (x - z) = 1
where A is symmetric. Expanding this out gives the required form:
x'*A*x - 2*z'*A*x + z'*A*z - 1 = 0
So linking back to my first equation (*), the MATLAB code for generating the matrices and vectors required are
Q = [cos(alpha), -sin(alpha); sin(alpha) cos(alpha)];
A = Q * diag([a^-2, b^-2]) * Q';
c = 2*A*z;
d = z'*A*z - 1;

8 Kommentare

Wajahat
Wajahat am 1 Mai 2012
Hi Richard,
Thanks a lot for your quick response.
Your answer is really helpful, but it my case, for the non-zero center the equation will become:
A(x-u)^2+2B(x-u)(y-v)+C(y-v)^2=1
where (u,v) is the center of the ellipse and with known Orientation and major and minor axes.
If I use your answer above, I get, as you mentioned, a symmetric matrix A and a vector c, where as I expect all the three coefficients (A,B and C) to be numbers only.
An example is:
u v A B C
464.64 315.81 0.108858 0.0335565 0.0628821
Any help on this?
Richard Brown
Richard Brown am 1 Mai 2012
Ah, that's a trivial modification (and is there in my answer in the penultimate equation). The coefficients you want are the entries of the symmetric matrix A.
i.e. your A = A(1,1), your B = A(1,2), and your C = A(2,2)
Wajahat
Wajahat am 1 Mai 2012
Thanks once again.
That solved my problem.
One last question though, the A(1,2) = B or B/2 ? The term in the equation is ... 2B(x-......
Richard Brown
Richard Brown am 1 Mai 2012
A(1,2) = B - when you expand out the quadratic, that term appears twice
Wajahat
Wajahat am 1 Mai 2012
That was great help Richard.
Have a good day...
Wajahat
Wajahat am 2 Mai 2012
Hi Richard,
Do you have some clue how to find the coefficients u,v,a,b,c in a(x-u)(x-u)+2b(x-u)(y-v)+c(y-v)(y-v)=1 directly from a point set. Perhaps using matlab's least squares curve fitting etc?
I have tried the method you describe above, but it is not giving me the correct results. I want to verify if the coefficients are same both way.
Richard Brown
Richard Brown am 2 Mai 2012
In all honesty, I would recommend using the code that I posted a link to fit your ellipse - it fits the ellipse using nonlinear least squares, i.e. actually minimising the sums of squared perpendicular distances to the ellipse.
If you try to use linear least squares directly on the coefficients of the equation, it is far less clear what you are actually minimising, and depending on your data, your results can be not good.
If you're having trouble, feel free to post your data, and I'll take a look
Wajahat
Wajahat am 2 Mai 2012
Hi Richard
Thanks for the offer.
I have sent my data to your email( the one mentioned here on MatlabCentral) along with some sample images.
Best Regards
Wajahat

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Mathematics and Optimization finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by