LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help fitting an ellipse

Hi all,

 

My problem is as follows: I acquire a number of data points which when plotted has the shape of an ellipse (please check the attached pic). It is possible to fit an ellipse yet the fits are not that good. So the idea we had is to exclude some of the central data. That is to find the mean and the standard deviation (SD) then use the SD (or multiple of the SD) as a threshold to exclude data. This did not work as expected; when plotting the thresholded data many of the data points were below the threshold! So my question, does anyone has in a mind an idea of how to exclude the central data points? 

 

Thanks in advance

0 Kudos
Message 1 of 8
(4,324 Views)

Hi

 

Have you found a solution?

 

I'm not sure if the following links help you:

Ellipse Fitting

http://forums.ni.com/t5/Machine-Vision/ELLIPSE-FITTING/td-p/1574258


And a google search brought up a lot of scripts for matlab. If you also have matlab installed on your system this could be a solution.

http://zone.ni.com/reference/de-XX/help/371361J-0113/gmath/matlab_script_node/

 

What do you mean by:

when plotting the thresholded data many of the data points were below the threshold!

 

Not all data was filtered as set by the threshold? Too much data was filtered?

 

Is it possible to attach the filter VI you implemented?

 

Best regards

Raphael

0 Kudos
Message 2 of 8
(4,260 Views)

Hi,

 

actually am I aware of the link you provided. My problem is not with the fitting as much as in the data I fit. The thing is that I collect x and y data points that when plotted have the shape of an ellipse. If you want to get a good fit then you are only interested in the data points that forms the edges of this ellipse (i.e.. The data that outline the ellipse). For this I used the idea that I mentioned. Please ignore the threshold issue for the moment as this was fixed but still the final result after filtering is far away from an ellipse

 

 

0 Kudos
Message 3 of 8
(4,250 Views)

I just got an (maybe stupid and non mathematical) idea...

 

What is the result of the ellipse fitting of the unfiltered data? Is the ellipse placed completely wrong or does it fit the data with just too small radii? If the latter is the case maybe you could iteratively filter out the data inside the ellipse. Thus the next time the fit ellipse function will place an ellipse with bigger radii and the inner data points can be filtered again. The iteration could be aborted if the numbers of data points outside and inside the ellipse are the same.

 

Just a quick idea before we need to dig deeper into mathematical solutions...

 

 

.... edit

The number of data points outside and inside the ellipse is probably always quite similiar before filtering the data...

0 Kudos
Message 4 of 8
(4,245 Views)

Actually I think you need to redefine the problem. You do not want to fit an ellipse - because an ellipse doess not describe the internal points, which are numerous.

 

The problem you may wish to be solving is: What is the equation of the ellipse with the minimum area that just encompasses all the points?

 

Alternatively, since on your plot we can't see how many internal points there are at different locations, you may in fact have a 3D problem where the density of points (d) is a function of X and Y. Then the question might be:

 

What is the best fit for a 2-dimensional Gaussian Distribution (of elliptical cross section) that describes the probability of finding a point in the rectangle dx  by dy centered on X,Y?  As it seems from your data you donlt have an axis rotation, could you just compute the mean and standard deviation of the X values, and the mean and standard deviation of the Y values? The ratio of the X and Y standrad deviations will suggest to you the ratio of the major to minor axes of the ellipse. Then the scaling of it is matter of state. How many points do you want to encompass? What is the penalty for not encompassing a few? Is it OK if you encompass everything up to 3 sigma?

 

I don't have a solution, as I got here Googling the simpler problem of how to best-fir and ellipse to X,Y data that I know is on an ellipse.

0 Kudos
Message 5 of 8
(4,192 Views)

@mssm22 wrote:
[...] The thing is that I collect x and y data points that when plotted have the shape of an ellipse. If you want to get a good fit then you are only interested in the data points that forms the edges of this ellipse (i.e.. The data that outline the ellipse). For this I used the idea that I mentioned :
[...] The idea we had is to exclude some of the central data. That is to find the mean and the standard deviation (SD) then use the SD (or multiple of the SD) as a threshold to exclude data. This did not work as expected; when plotting the thresholded data many of the data points were below the threshold! So my question, does anyone has in a mind an idea of how to exclude the central data points?

 

 


Hi,

 

to sum up your problem:

 

1# calculate "outline" points

 

2# fit those points to an ellipse or super-ellipse.

 

 

As far as I have understood, it's step 1# which bothers you.

 

Can you please define the term "outline"?

 

 

One possible outline would be the convex hull of your data points shown.

 

 

 

 

Alex

 

 

0 Kudos
Message 6 of 8
(4,159 Views)

You say "determine the standard deviation", but of what, and what is the mean that it it the standard deviation from?

 

Here is an idea:

 

It takes a minimum of 5 points to fit an ellipse. So start by picking the five points with largest x^2 + y^2  and fit an ellipse to that.

(You will be inverting a 5x5 matrix .  I am doing that right now on my PC and takes microseconds! )

 

Then gradually include more of succesively smaller radius and best fit an ellipse to those. there is a way to just update the ellipse parameters , and update the inverse of the above 5 x 5 matrix which can be done without inverting it anew) every time you add a new point, rather than having to solve the 5 X 5  system again.

 

But the question remains: How do you know when you have found the ellipse you want? What is the criterion for being "happy" with a result?

0 Kudos
Message 7 of 8
(4,142 Views)

As a matter of interest, my problem, which I just solved, was to do with automatic testing of a phase-shift network.

 

I put a sine wave of a given frequency in, and out should come two sinewaves in quadrature and of equal amplitude.

 

So I digitally sample the two outputs into a PC and then process them to determine phase and amplitude error.

 

       But how?

 

I tried correlating digitally with an internally generated sine and cosine but this didn't  work as the frequency was not known accurately enough relative to the sample rate. So I tried first determining the fractional number of samples per cycle on average, in order to be able to digitally construct a reference.. This was fraught with problems too as the timing of the sampling was not regular enough and the frequency could be drifting. 

 

I finally realized that all samples, whenever sampled, should fit on an ellipse - a lissajou's figure. So I best-fit an ellipse to all 65536 data points I captured without needing to know anything about their timing, and got the albebraic parameters A1...5 of the ellipse in the form

 

A1 x^2 + A2y^2 +A3xy  + A4x + A5y = 1   

 

Then with a bit of tricky math I was able to convert the above A-coefficients to parametric coefficients ao, bo and dPhi of an ellipse in the form

 

   x = a0.cos(theta)+ x0;  y= bo.sin(theta+dPhi)+y0

 

whence I determined the quadrature error dPhi,  amplitude ratio error a0/b0 and DC offsets x0,y0

0 Kudos
Message 8 of 8
(4,139 Views)