# [AstroPy] Ellipse2D fit

Fabricio Ferrari fabricio.ferrari at gmail.com
Wed Feb 15 08:07:53 EST 2017

```yes of course, I did not paid attention. sorry :-D

I have been using Fitzgibbon, Pilu and Fischer  solution for fitting
ellipses, which is states the problem such that it can be written as and
eigenvalue equation (it is not iterative). Please, take a look for example
at

http://nicky.vanforeest.com/misc/fitEllipse/fitEllipse.html

The original paper I think it is:
http://cseweb.ucsd.edu/~mdailey/Face-Coord/ellipse-specific-fitting.pdf

regards.

F

..-. ..-.
Fabricio Ferrari       [www.ferrari.pro.br]
IMEF -  FURG
Rio Grande, RS
Brasil

2017-02-15 10:47 GMT-02:00 Andrzej Szary <aszary at gmail.com>:

> Dear Fabricio,
>
> Note that the DATA and MODEL parameters are different. For a good fit they
> should be similar. You can get better results using different fitter (*fi
> = fitting.SimplexLSQFitter()*), but it is still not good enough for my
> purpose (I need to find theta parameter).
>
> Best wishes
> Andrzej Szary
>
>
> >> On 15 February 2017 at 13:14, Fabricio Ferrari <
> fabricio.ferrari at gmail.com> wrote:
> >>
> >> Dear Andrzej
> >>
> >> here it seemed to work. Maybe the version you are using.
> >>
> >> Here I have:
> >>
> >>In [2]: np.__version__
> >>Out[2]: '1.11.1'
> >>
> >>In [4]: astropy.__version__
> >>Out[4]: u'1.2.1'
> >>
> >>My output:
> >>
> >>DATA:
> >>Model: Ellipse2D
> >>Inputs: (u'x', u'y')
> >>Outputs: (u'z',)
> >>Model set size: 1
> >>Parameters:
> >>    amplitude x_0 y_0  a   b  theta
> >>    --------- --- --- --- --- -----
> >>          1.0 0.0 0.0 2.0 1.0   0.0
> >>
> >>
> >>MODEL:
> >>Model: Ellipse2D
> >>Inputs: (u'x', u'y')
> >>Outputs: (u'z',)
> >>Model set size: 1
> >>Parameters:
> >>      amplitude    x_0 y_0  a   b  theta
> >>    -------------- --- --- --- --- -----
> >>    0.338211382114 0.1 0.1 3.0 2.0   0.2
> >>
> >>p.s. thank you for letting me know about the Ellipse2D fit, that I
> indeed need and did not >>know about.
> >>
> >>Regards
> >>Fabricio
>
>
> On 8 February 2017 at 16:40, Andrzej Szary <aszary at gmail.com> wrote:
>
>> Hello,
>>
>> I am struggling with  fitting an ellipse using Ellipse2D model. The
>> fitting procedure does not seem to have any effect on ellipse parameters
>> (maybe except amplitude).
>>
>> Please find a test code at the end of this email.
>>
>> Best wishes,
>> Andrzej Szary
>>
>>
>> import numpy as np
>> from astropy.modeling import models, fitting
>> import matplotlib.pyplot as pl
>>
>> # data
>> num = 100
>> x, y = np.meshgrid(np.linspace(-5., 5., num), np.linspace(-5, 5, num))
>> e0 = models.Ellipse2D(amplitude=1., x_0=0., y_0=0., a=2, b=1, theta=0.)
>> z0 = e0(x, y)
>> print 'DATA:\n', e0, '\n\n'
>>
>> # initial model
>> ei = models.Ellipse2D(amplitude=1., x_0=0.1, y_0=0.1, a=3, b=2, theta=0.2)
>> fi = fitting.LevMarLSQFitter()
>>
>> # fitted model?
>> e1 = fi(ei, x, y, z0)
>> z1 = e1(x, y)
>> print 'MODEL:\n', e1, '\n\n'
>>
>> pl.imshow(z0, extent=[-5, 5, -5, 5], alpha=0.5)
>> pl.imshow(z1, extent=[-5, 5, -5, 5], alpha=0.2)
>> pl.show()
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20170215/c29cf1e2/attachment.html>
```