问题
I regularly have upwards of 10^8 sets of ellipse fitting data to solve coming out of monte-carlo simulations by looping through the Halir & Flusser (Page 4, Figure 2) ellipse fitting algorithm. Is there a way of vectorizing the process/algorithm/function, so that I can send the lot at once to the function and it returns 10^8 solutions to the 10^8 sets? I want to stick with Halir & Flusser as it is very robust. Having used other ellipse-fitting methods, this one always returns ellipses I can further process.
function a = Halir(x,y)
% Reproduces the improved ellipse-specific fitting algorithm of:
% Radim Halir and Jan Flusser (1998) "Numerically Stable Direct Least Squares Fitting of Ellipses"
% a(1)x^2 + a(2)xy + a(3)y^2 + a(4)x + a(5)y + a(6) = 0
D1 = [x.^2, x.*y, y.^2];
D2 = [x, y, ones(size(x))];
S1 = D1'*D1;
S2 = D1'*D2;
S3 = D2'*D2;
T = -inv(S3)*S2';
M = S1+S2*T;
M = [M(3,:)./2; -M(2,:); M(1,:)./2];
[evec, eval] = eig(M);
cond = 4*evec(1,:).*evec(3,:)-evec(2,:).^2;
a1 = evec(:,find(cond>0));
a = [a1; T*a1];
来源:https://stackoverflow.com/questions/54509198/matlab-multiple-halir-ellipse-fitting-using-vectorization