-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTaubinSVD.m
More file actions
35 lines (31 loc) · 1.22 KB
/
TaubinSVD.m
File metadata and controls
35 lines (31 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
% from: https://people.cas.uab.edu/~mosya/cl/MATLABcircle.html
function Par = TaubinSVD(XY)
%--------------------------------------------------------------------------
%
% Algebraic circle fit by Taubin
% G. Taubin, "Estimation Of Planar Curves, Surfaces And Nonplanar
% Space Curves Defined By Implicit Equations, With
% Applications To Edge And Range Image Segmentation",
% IEEE Trans. PAMI, Vol. 13, pages 1115-1138, (1991)
%
% Input: XY(n,2) is the array of coordinates of n points x(i)=XY(i,1), y(i)=XY(i,2)
%
% Output: Par = [a b R] is the fitting circle:
% center (a,b) and radius R
%
% Note: this is a version optimized for stability, not for speed
%
%--------------------------------------------------------------------------
centroid = mean(XY); % the centroid of the data set
X = XY(:,1) - centroid(1); % centering data
Y = XY(:,2) - centroid(2); % centering data
Z = X.*X + Y.*Y;
Zmean = mean(Z);
Z0 = (Z-Zmean)/(2*sqrt(Zmean));
ZXY = [Z0 X Y];
[U,S,V]=svd(ZXY,0);
A = V(:,3);
A(1) = A(1)/(2*sqrt(Zmean));
A = [A ; -Zmean*A(1)];
Par = [-(A(2:3))'/A(1)/2+centroid , sqrt(A(2)*A(2)+A(3)*A(3)-4*A(1)*A(4))/abs(A(1))/2];
end % TaubinSVD