Get ellipse function from datapoints

25 views (last 30 days)
Hi guys,
i want to get an ellipse function from given data.
001.PNG
In this data, outliers are removed. Now I want to get the function of an approximate ellipse, which is around the points. It is clear, that there will be some inaccuracy.
The final ellipse should look (just as my initial guess):
002.PNG
My former approaches was to use rmoutliers to delete the inner points, but there isnt any option to circular fit points, so a "window" will be the result.
003.PNG
With this (purple) points, i ran some ellipse fit functions from matlab file exchange.
All the results werent satisfying.
How can I (1.) remove the inner points of the data, to get an ellipse (and not this x-y-window) and (2.) how can I detect the ellipse function from the data?

Accepted Answer

llueg
llueg on 24 Jul 2019
You can use Eigen decomposition to come up with the parameters for the ellipse. You then scale the size of the ellipse based on how many standard deviations you want to include. The components of the ellipse are computed from the eigen decomposition of your data matrix. I pretty much copied the code below from here.
%for demonstration, I generated some data: 100 points in 2D
X = normrnd(0,2,[100 2]);
%the mean should be at zero
Mu = mean(X);
X0 = bsxfun(@minus, X, Mu);
%scale the size of the ellipse based on standard deviatioon
STD = 2;
%covers around 95% of population
conf = 2*normcdf(STD)-1;
%inverse chi-squared with dof=dimensions
scale = chi2inv(conf,2);
Cov = cov(X0) * scale;
% eigen decomposition [sorted by eigen values]
[V, D] = eig( Cov );
[D, order] = sort(diag(D), 'descend');
D = diag(D);
V = V(:, order);
t = linspace(0,2*pi,100);
% unit circle
e = [cos(t) ; sin(t)];
% scale eigenvectors
VV = V*sqrt(D);
% project circle back to orig space
e = bsxfun(@plus, VV*e, Mu');
% plot cov and major/minor axes
figure(1)
plot(e(1,:), e(2,:), 'Color','b');
hold on
scatter(X(:,1),X(:,2))
hold off
  3 Comments
Marc Gebhardt
Marc Gebhardt on 2 Aug 2019
It works.
Now i need the function of main and minor axis.
The centre i got already from variable Mu out of the code.
I tried a lot but could not read out the four necessary variables (offset and increase for both axis) from the other variables.
How can I calculate them?
Regards
Marc Gebhardt
Marc Gebhardt on 2 Aug 2019
I got it myself. These are the Elements v(1,2) and 1/v(2,1).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!