hello Dr.Yi
This code is working good for N<=150
but when N exceeds this limit, a nonsense happens
Is there any improvement to the code considering this error?

For my tasks this function works better than the others I've tried so far. Thank you very much Ohad!!
@Aritra: To run this function on a binary image you have to run:
[X Y] = ind2sub(size(img),find(img));
E = fit_ellipse(x,y);
then you can do:
if E.long_axis > 0
[X, Y] = calcEllipse(E, 360);
end
To plot it the ellipse:
plot(Y, X);
The function calcEllipse:
function [X,Y] = calcEllipse(varargin)
% function [X,Y] = calculateEllipse(x, y, a, b, angle, steps)
%# This functions returns points to draw an ellipse
%#
%# @param x X coordinate
%# @param y Y coordinate
%# @param a Semimajor axis
%# @param b Semiminor axis
%# @param angle Angle of the ellipse (in rad)
%#
% Source: http://stackoverflow.com/questions/2153768/draw-ellipse-and-ellipsoid-in-matlab/24531259#24531259
% Modified by Christian FĂ¤ssler
steps = 360;
if nargin == 1 || nargin == 2
x = varargin{1}.X0_in;
y = varargin{1}.Y0_in;
a = varargin{1}.a;
b = varargin{1}.b;
angle = varargin{1}.phi;
if nargin == 2
steps = varargin{2};
end
else if nargin == 5 || nargin == 6
x = varargin{1};
y = varargin{2};
a = varargin{3};
b = varargin{4};
angle = varargin{5};
if nargin == 6
steps = varargin{6};
end
else
error('Wrong input');
end
end
beta = -angle;
sinbeta = sin(beta);
cosbeta = cos(beta);
alpha = linspace(0, 2*pi, steps)';
sinalpha = sin(alpha);
cosalpha = cos(alpha);
X = round(x + (a * cosalpha * cosbeta - b * sinalpha * sinbeta));
Y = round(y + (a * cosalpha * sinbeta + b * sinalpha * cosbeta));
if nargout==1, X = [X Y]; end
end

5

07 Jul 2014

fit_ellipse
Find the best fit for an ellipse using a given set of points (a closed contour).

Can anyone provide a clear idea about how to implement this practically?
For example if I want to find ellipses in an binary image say bw, how to run this code on the image to get the ellipses?
As I see there is no way to provide the matrix name as a input argument.
And if somebody could explain the input arguments "Input: x,y - a set of points in 2 column vectors. AT LEAST 5 points are needed !"
I mean this statement a bit elaborately it will be very helpful.

I found that for my system, the covariance matrix was growing like crazy (P_k~10^8*P_k-1) and was getting complex.
Try adjusting the alpha parameter. 10e-3 was way too small for my system, and 0.1 was the bare minimum that I could avoid the covariance issues. 0.15 seemed to work best.
in general, alpha is recommended to be between 10e-3 and 1.

Hi everybody!
I really have not understood this code yet. In my case, I also study on EKF for GPS data that I want to apply EKF to due with noise and missing data in GPS data. I have one GPS data columm with more than 2000 of length. Who could show me how to do it?
Thank you so much for your kinds

Comment only