3

I create an algorithm recognizing ellipses in images.

enter image description here

I have five coordinates (points) possible ellipse.

(8.8) (7.4) (6.3) (3.6) and (2.2)

I use the formula of the conical section of the second order:

$Ax ^ 2 + Bxy + Cy ^ 2 + Dx + Ey + F = 0$

And determines the type of conic section by the value of the discriminant.

$B ^ 2-4AC$

Where, if the sign of the value < 0, then this ellipse.

On the basis of the coordinate values I find A, B, C, D, E, F. (Calculates them here)

A = 0.0763889 
B = -0.0902778 
C = 0.0763889 
D = -0.312500 
E = -0.312500 
F = 1.00000

But I do not know what to do next calculations.

How do I need to get the coordinates of the center of the ellipse, the length of its two axes, and rotation about the coordinate axes?

Thank you!

Bérénice
  • 9,367
Qulery
  • 165
  • 1
    Substitute $x-x_c,y-y_c$ for $x,y$ and cancel the terms $Dx,Ey$. This centers the ellipse. Then substitute $x\cos(\theta)-y\sin(\theta),x\sin(\theta)+y\cos(\theta)$ for $x,y$, and cancel the term $Bxy$. This orients the ellipse and gives the angle. Then put in the form $x^2/a^2+y^2/b^2=1$, giving the axis lengths. –  Jun 13 '16 at 19:56
  • @YvesDaoust, Thanks for the answer! You could write an example using my data (values)? – Qulery Jun 13 '16 at 20:09
  • Hehe, I am not doing your whole homework. –  Jun 13 '16 at 21:00
  • @Yves Daoust, Nevertheless thank you! – Qulery Jun 13 '16 at 21:26
  • 1
    The equation is $$\left( \frac { \sqrt { 2 } }{ 2 } \cdot \left( x+y-10 \right) \right) ^{ 2 }+4\cdot \left( \frac { \sqrt { 2 } }{ 2 } \cdot \left( y-x \right) \right) ^{ 2 }=18$$ – PunkZebra Jun 13 '16 at 22:05

2 Answers2

1

8,8 and 2,2 are the endpoints of the major axis.

The center is at (5,5)

the length major axis is 6 sqrt 2

The angle of rotation is 45 degrees.

Using the substitution u = x+y, v = x-y Our points in u,v space are (16,0),(11,3),(9,3),(9,-3),(4,0)

$\frac{(u-5)^2}{6^2} + \frac{v^2}{b^2} = 1\\ \frac {1}{36} + \frac{v^2}{b^2} = 1\\ b = \frac{18}{\sqrt{35}}$

And the length of the minor axis = $b \sqrt 2$

Had the points not been so carefully chosen to make this easy to solve, I don't think what I have done generalizes.

If you have the equation $A x^2 + Bxy + Cy^2 + Dx + Ey + F = 0$

$x = u \cos \theta - v \sin\theta\\ y = u \sin \theta + v \cos\theta$

Find $\theta$ such that the uv cross term drops away.

$(C-A) \sin 2\theta + B \cos 2\theta = 0\\ \theta = \frac 12 \tan^{-1} \frac B{C-A}$

Then complete the square to center (u,v). You will need to plug the coordinates of the center in (u,v) space back into the transformation to find them in x,y space.

Put into standard form to find the length of the major and minor axes.

Doug M
  • 57,877
  • Thanks for the answer! Points are an example. The rotation angle may vary between 45 and coordinates of five points may be different. How can I calculate the angle, if it had not been known endpoints of the major axis? – Qulery Jun 13 '16 at 20:06
  • 1
    I have given some information on finding the angle if you have an equation in the $A x^2 + Bxy + Cy^2 \cdots$ format – Doug M Jun 13 '16 at 20:30
1

For $U(x,y) = Ax ^ 2 + Bxy + Cy ^ 2 + Dx + Ey + F = 0$ the center is located at

$$ \left. \begin{align} \frac{\partial U}{\partial x} & = 0 \\\frac{\partial U}{\partial y} & = 0 \end{align} \right\} \begin{aligned} x_c & = \frac{B E - 2 C D}{4 A C - B^2} \\ y_c &= \frac{B D -2 A E}{4 A C - B^2} \end{aligned} $$

This transforms the equation into

$$ A (x-x_c)^2 + B (x-x_c) (y-y_c) + C (y-y_c)^2 + F^\star = 0 $$

where $$F^\star = F + \frac{D (B E-C D)-A E^2}{4 A C - B^2} $$

The rotation angle is then found by $$\theta = \frac{1}{2} \arctan \left( \frac{B}{A-C} \right) $$

The polar distance at angle $\theta$ is found by rotation of the axes. The major and minor axes are

$$r = \sqrt{ \frac{-2 F^\star}{A+C \pm \sqrt{B^2+(A-C)^2}} }$$

With the values from your question I get $r=4.2426406871192851 $ and $r=2.1514113001014558$

John Alexiou
  • 13,816
  • Thank you! In your answer I was able to find everything I need! Thank you for your clear answer! – Qulery Jun 13 '16 at 22:09
  • The problem :( I can not get to determine the length of the two axes in the Cartesian coordinate system, or the distance from the center of the ellipse to the short and long axis, to get a real axis coordinates of points How can I identify them? – Qulery Jun 13 '16 at 23:47
  • 1
    See edited answer for the major and minor axes (min. max radius). – John Alexiou Jun 14 '16 at 00:05
  • Exactly what is needed! Working! Many thanks! You made my day! – Qulery Jun 14 '16 at 00:17
  • Hello! There is a problem with the angle. Sometimes returns the wrong angle. Example of the image. I spent a lot of time that would have to find the reason and the law, but could not. Perhaps you can guess what's the problem? I'll be very grateful! https://swinechat.com/other/rotate_problem_ellipse.jpg – Qulery Jun 24 '16 at 23:30
  • How do I get the correct angle of rotation in all cases? – Qulery Jun 24 '16 at 23:33
  • Did you implement it with the atan2(y, x) function? – John Alexiou Jun 26 '16 at 14:02
  • Thank you for having responded! I created a separate issue for example. There is more information. http://math.stackexchange.com/questions/1839510/how-to-get-the-correct-angle-of-the-ellipse-after-approximation – Qulery Jun 26 '16 at 14:07
  • On the question page (link above) is an example of an algorithm, where you can see the implementation of – Qulery Jun 26 '16 at 14:13