0
$\begingroup$

I am trying to fit points of an ellipse to my model using pseudoinverse technique described in this paper (it's in section 4.1). I'm sure that my understanding is wrong, please, could you give me guidelines what I am doing wrong?

My test image is this. I use MATLAB code to calculate the A and b matrices, and the parameter vector, but every time I got A = -0.0000 B = 0.0000 D =-0.0000 E = 0.5000 F = 0.0000 as result, so C = 1 - A = 1, but this gives $y^2+y=0$ as fitted conic which is a parabola not and ellipse.

First, I get 5 random samples from the edge of the ellipse. Than I put it into the matrix X. I fill X2, so $\left(x_i^2-y_i^2, 2x_iy_i, 2x_i 2y_i, 1\right)$ is the ith row. The b matrix is fille that $y_i$ is the ith row. Then I calculate $p=(A^TA)^{-1}A^Tb$. Is this the correct usage of the method described in the article? If it is, why do I get the equation of a parabola instead?

My MATLAB code:

I = imread('Ellipse1.gif');
I = bwmorph(I, 'thin', Inf);
imagesc(I);hold on;
[y,x] = find(I);
idx = randsample(length(y),5);
X = [ x(idx(1)), y(idx(1)); x(idx(2)), y(idx(2)); x(idx(3)), y(idx(3)); x(idx(4)), (idx(4)); x(idx(5)), y(idx(5)) ];
X2 = [ X(1,1)^2-X(1,2)^2, 2*X(1,1)*X(1,2), 2*X(1,1), 2*X(1,2), 1;
X(2,1)^2-X(2,2)^2, 2*X(2,1)*X(2,2), 2*X(2,1), 2*X(2,2), 1;
X(3,1)^2-X(3,2)^2, 2*X(3,1)*X(3,2), 2*X(3,1), 2*X(3,2), 1;
X(4,1)^2-X(4,2)^2, 2*X(4,1)*X(4,2), 2*X(4,1), 2*X(4,2), 1;
X(5,1)^2-X(5,2)^2, 2*X(5,1)*X(5,2), 2*X(5,1), 2*X(5,2), 1 ];
b = [ X(1,2); X(2,2); X(3,2); X(4,2); X(5,2) ];
p = (X2'*X2)\X2'*b

$\endgroup$
2
  • $\begingroup$ We don't debug code. You might try math.stackexchange.com/questions?sort=active but make an effort to give more background. $\endgroup$
    – Will Jagy
    Jan 8, 2012 at 22:12
  • $\begingroup$ I removed the sums-of-squares tag because it was not clear how that was related. If it is related somehow, please make the connection clearer. $\endgroup$
    – Noah Stein
    Jan 8, 2012 at 23:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.