comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Ellipse fitting?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Ellipse fitting? [message #66407] Tue, 12 May 2009 13:36 Go to next message
robparker23 is currently offline  robparker23
Messages: 10
Registered: March 2009
Junior Member
Hi,

I was hoping that someone could help with this.

I have a satellite footprint which is more or less elliptical. I have
the 4 coordinates of the top, bottom, left and right-most points and
want to fit an ellipse to these 4 coordinates.

I've put a diagram here to explain: http://img217.imageshack.us/img217/5048/ellipse.png

I've googled this quite a bit and there seem to be lots of ways to fit
ellipses to complicated data sets using techniques like optimal
estimation but I can't find an easy/quick way of doing it. To do this
manually I think I could just take the equation for an ellipse and
adjust it to fit but I need to do this automatically for a large
number of points where the shape of the ellipse will change depending
on the location.

This gets slightly more complicated (doesn't it always) as the shape
may not quite be an ellipse due to the geometry of the satellite (it
might have one side slightly "fatter" than the other) and it might be
titled at an angle (so not horizontal).

Does IDL have any ellipse fitting capabilities built in or is anyone
familar with a solution that might work?

Cheers
Re: Ellipse fitting [message #72461 is a reply to message #66407] Thu, 09 September 2010 11:55 Go to previous message
Oriol Güell Riera is currently offline  Oriol Güell Riera
Messages: 7
Registered: September 2010
Junior Member
On 9 sep, 15:50, Jeremy Bailin <astroco...@gmail.com> wrote:
> On Sep 9, 7:18 am, Oriol Güell Riera <oriolguellri...@gmail.com>
> wrote:
>
>
>
>> Hi all,
>> I've got a problem when I try to find the orientation of a fitted
>> ellipse of a region of interest (http://www.dfanning.com/ip_tips/
>> fit_ellipse.html).
>> I've got an stack of images of an ellipse rotating. My problem arises
>> when I try to find the eigenvectors of the covariance matrix, the
>> signs of the components of them change randomly. In other words, I
>> start with my ellipse in the 3rd quadrant. The first image gives the
>> correct signs for the components of the principal eigenvector, but the
>> second image doesn't give the signs of the components well, so in this
>> case the eigenvector is located in the 4th quadrant, but my ellipse
>> still stands in the 3rd quadrant!
>> I don't know if I have explained my problem correctly. The problem
>> comes from the indeterminacy of the signs of the eigenvectors. If they
>> had the correct signs, I would use the atan2 function, which will give
>> the correct orientation. However, the signs aren't correct, so I can't
>> get the orientation of the ellipse after a whole rotation.
>> Thank you very much
>
> I can see how you might alternate between 3rd and 1st quadrant (or
> alternately 4th and 2nd quadrant), but not how you would go between
> the 3rd and 4th without the ellipse itself rotating.
>
> How best to deal with it depends on what you're planning on doing with
> the eigenvectors. It sounds like you're trying to measure the angle of
> the major axis and compare it between images. In that case, I'd just
> use atan2 and then do a check afterwards to see whether the angle has
> changed by more than 90degrees - if so, add/subtract 180degrees from
> the angle in the second image as appropriate (of course, that assumes
> that the ellipse isn't *actually* changing by more than 90degrees
> between images). If you really need the eigenvectors, then do
> something similar - take the dot product and if it's negative, use the
> negative of the eigenvector.
>
> -Jeremy.

You're true, I made a typo when I wrote 3rd-4th quadrant, sorry! And
you're right, I've got a video of an ellipse rotating in the xy plane.
I've transformed it in an image stack and I'm tracking the centroid
and the orientation of the ellipse.
I will try the combinations of the signs of the eigenvectors and I'm
going to choose the one with the smaller angular difference. The
ellipse shouldn't change by more than 90 degress, I made the image
stack with a lot of frames per second to avoid these problems. In
fact, the difference is 0.01 radians more or less, so there should be
no problems
I also tried to use the atan2 function and I had the same problem, but
I was wondering if there was some kind of solution for the problem of
the signs. I had no hope in finding this solution because, but I
decided to ask you to check it.

I'll tell you if I have solved this problem soon.

Thank you very much for your help again.

Oriol
Re: Ellipse fitting [message #72470 is a reply to message #66407] Thu, 09 September 2010 06:50 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Sep 9, 7:18 am, Oriol Güell Riera <oriolguellri...@gmail.com>
wrote:
> Hi all,
> I've got a problem when I try to find the orientation of a fitted
> ellipse of a region of interest (http://www.dfanning.com/ip_tips/
> fit_ellipse.html).
> I've got an stack of images of an ellipse rotating. My problem arises
> when I try to find the eigenvectors of the covariance matrix, the
> signs of the components of them change randomly. In other words, I
> start with my ellipse in the 3rd quadrant. The first image gives the
> correct signs for the components of the principal eigenvector, but the
> second image doesn't give the signs of the components well, so in this
> case the eigenvector is located in the 4th quadrant, but my ellipse
> still stands in the 3rd quadrant!
> I don't know if I have explained my problem correctly. The problem
> comes from the indeterminacy of the signs of the eigenvectors. If they
> had the correct signs, I would use the atan2 function, which will give
> the correct orientation. However, the signs aren't correct, so I can't
> get the orientation of the ellipse after a whole rotation.
> Thank you very much

I can see how you might alternate between 3rd and 1st quadrant (or
alternately 4th and 2nd quadrant), but not how you would go between
the 3rd and 4th without the ellipse itself rotating.

How best to deal with it depends on what you're planning on doing with
the eigenvectors. It sounds like you're trying to measure the angle of
the major axis and compare it between images. In that case, I'd just
use atan2 and then do a check afterwards to see whether the angle has
changed by more than 90degrees - if so, add/subtract 180degrees from
the angle in the second image as appropriate (of course, that assumes
that the ellipse isn't *actually* changing by more than 90degrees
between images). If you really need the eigenvectors, then do
something similar - take the dot product and if it's negative, use the
negative of the eigenvector.

-Jeremy.
Re: Ellipse fitting [message #72471 is a reply to message #66407] Thu, 09 September 2010 06:29 Go to previous message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article
<a8e942ee-0554-42d6-9bad-caf77b03935b@a11g2000vbn.googlegroups.com>,
Oriol G�ell Riera <oriolguellriera@gmail.com> wrote:

> Hi all,
> I've got a problem when I try to find the orientation of a fitted
> ellipse of a region of interest (http://www.dfanning.com/ip_tips/
> fit_ellipse.html).
> I've got an stack of images of an ellipse rotating. My problem arises
> when I try to find the eigenvectors of the covariance matrix, the
> signs of the components of them change randomly. In other words, I
> start with my ellipse in the 3rd quadrant. The first image gives the
> correct signs for the components of the principal eigenvector, but the
> second image doesn't give the signs of the components well, so in this
> case the eigenvector is located in the 4th quadrant, but my ellipse
> still stands in the 3rd quadrant!
> I don't know if I have explained my problem correctly. The problem
> comes from the indeterminacy of the signs of the eigenvectors. If they
> had the correct signs, I would use the atan2 function, which will give
> the correct orientation. However, the signs aren't correct, so I can't
> get the orientation of the ellipse after a whole rotation.
> Thank you very much

As you say, the signs of the eigenvectors are indeterminate.

If the rotations between successive instances are small, you should
be able to check which option gives you the smaller rotation.
That is, check ATAN(y, x) and ATAN(-y, -x) and see which
gives the smaller angular difference from the previous orientation.
You have to be careful when cross the origin.

Ken Bowman
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Error in graphics webinar example
Next Topic: widget_list() question

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 08:29:19 PDT 2025

Total time taken to generate the page: 0.00794 seconds