Code covered by the BSD License  

Highlights from
fitcircle.m

4.66667

4.7 | 3 ratings Rate this file 35 Downloads (last 30 days) File Size: 39.26 KB File ID: #15060
image thumbnail

fitcircle.m

by Richard Brown

 

20 May 2007 (Updated 21 May 2007)

Fits circles to 2D data using nonlinear least squares to minimise geometric error

| Watch this File

File Information
Description

Although a linear least squares fit of a circle to 2D data can be computed, this is not the solution which minimizes the distances from the points to the fitted circle (geometric error). The linear solution minimizes the algebraic error of a function something like
f(x) = ax'x + b'x + c = 0

Minising the geometric error is a nonlinear least squares problem. fitcircle allows you to compute either - it uses the algebraic fit as the initial guess for the geometric error minimization.

e.g.
x = randn(2, 10);
% Linear least squares fit
[z, r] = fitcircle(x, 'linear')

% True best fit (minimizing geometric error)
[z, r] = fitcircle(x)

For more information look at the published demo file.

This submission is based on the paper:
"Least-squares fitting of circles and ellipses", W. Gander, G. H. Golub, R. Strebel, BIT Numerical Mathematics, Springer 1994

A similar submission for ellipses should be forthcoming

MATLAB release MATLAB 7.1.0 (R14SP3)
Other requirements Should work for R14 onwards. Changes to make it work for earlier releases are probably fairly straightforward (e.g. replacing boolean false and true with 0, 1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
23 May 2007 Ali Özgül

Documentation:
+Publis M-files application and theory (5)
+Graphical program interface (5)
+Workable program description (5)
+Works references (3)

Programming:
+M-files complexity (3)
+Mlint error message (5)
+Help problems (4)
+Filename of clashes (5)
+Clone the code line (5)
+Program's symbolic manuscript (3)
+Program samples and runing test (5)
+System requirements (5)
+Program running speed (4)

Files archive:
Seleceted file name (5)
Per files comment (5)
All files usefuly (4)

Thanks:
Very nice application and documentation.
Good works.

23 Mar 2009 Levi Kilcher

This function is fantastic!

Great work, thanks.

19 Oct 2009 Kristopher White

Great work.

26 Apr 2010 SengChoy Liew

if i have a gray scale picture with circles of various diameter touching each other. How can i make use of this fitting to evaluate the distribution in histogram of circles in that pictures ?

I could not find any codes in image processing toolbox for it.

Anyone out there for help ?

30 Aug 2011 Brian Wheeler

To test thus function I fed it data for a 360 point unit circle. As expected it returned a unit circle centered on zero.

Distorting one point of the circle to a radius of 6 gave expected results:
radius 1.01408739256055
center [ 3.76743045176789e-17 0.0281775669475842]

Distorting the same point of the circle to a radius of 7 gave UNEXPECTED results:
radius 3.258619140676808
center [1.25049755875451e-15 3.17478833187820]

Thoughts anyone?

18 Sep 2011 Richard Brown

Hi Brian

This code computes a least squares fit, which is not robust to large outliers - the results you got are not unexpected, nor are they wrong.

Because the objective being minimised is a function of the square of the distance, big outliers will skew the fit. If your data is known to have significant outliers, least squares is not a good choice of objective to minimise.

cheers,

Richard

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
approximation Richard Brown 22 Oct 2008 09:13:16
interpolation Richard Brown 22 Oct 2008 09:13:16
fitcircle Richard Brown 22 Oct 2008 09:13:16
circle Richard Brown 22 Oct 2008 09:13:16
least squares Richard Brown 22 Oct 2008 09:13:16
gauss newton Richard Brown 22 Oct 2008 09:13:17
fitcircle mathieu 31 Jan 2012 09:44:59

Contact us at files@mathworks.com