Comments on: Fitting a Circle, easily. https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/?s_tid=feedtopost Jiro and Sean share favorite user-contributed submissions from the File Exchange. Tue, 10 May 2016 19:15:52 +0000 hourly 1 https://wordpress.org/?v=6.2.2 By: bshoelso https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-14428 Tue, 21 Feb 2012 18:12:23 +0000 https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-14428 @WDM:
I’m not sure I understand what your question is. In the example I used above, I only had several points on (or near) the arc of a circle. I used those points to calculate the best-fit circle through those arc points.
Brett

]]>
By: bshoelso https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-14402 Tue, 24 Jan 2012 21:33:22 +0000 https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-14402 See my reply to ko’s ellipse-fitting question earlier.

]]>
By: Brett https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-13901 Sat, 23 Oct 2010 14:31:29 +0000 https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-13901 Motahhare,
I don’t know why that link is no longer valid; perhaps the author pulled the file. However, if you search the File Exchange for “fit circle,” you should find several options that will do what you need.

]]>
By: Motahhare https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-13900 Fri, 22 Oct 2010 20:45:23 +0000 https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-13900 Hi
I have the same problem as nadine had,but the link which Bob was given is now corrupt & I can’t find a good answer.
would you help me please?!
tnx

]]>
By: Brett https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-13894 Mon, 18 Oct 2010 14:50:54 +0000 https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-13894 Quinno,
In a “Hough” world, one would have to parameterize the rectangle or polynomial and create the Hough implementation himself or herself. But the MATLAB function POLYFIT might be useful for you as well.

]]>
By: Quinno https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-13701 Mon, 19 Jul 2010 12:19:01 +0000 https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-13701 I would like to create a best-fit rectangle to a object or polygon. how can i do that?

]]>
By: Bill https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-13137 Thu, 23 Apr 2009 03:01:19 +0000 https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-13137 CIRCLES
9 circles .
Each Circle lettered, A through I, has it’s own number value from 1 through 9.Sums of circles that overlap at that point.
for example… 5 is the sum of circles A and C. What are A and C’s Values?
How do you arrive at the values?

]]>
By: Brett https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-13002 Mon, 19 Jan 2009 19:29:35 +0000 https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-13002 BWBOUNDARIES operates on a binary image. If possible, I would avoid the route of converting your raw data to an image file if the only reason for doing so would be extracting and fitting the data for overlapping circles in preparation for re-plotting them.

I haven’t seen your data, but my initial thought is use some other (clustering?) approach on the raw data to associate points with one of the two circles, then fitting them independently.

If you do need to extract xs and ys from the output of BWBOUNDARIES (which returns a cell array of x-y- data), you can easily do so. For instance, the boundaries of the first object in the bw image IMG can be plotted with:

b = bwboundaries(img);
figure;
plot(b{1}(:,1),b{1}(:,2),’r.’);

Cheers,
Brett

]]>
By: Lee https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-12998 Mon, 19 Jan 2009 16:44:28 +0000 https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-12998 “If I recall my geometry, one would calculate the diameter of the best-fit circle by doubling the best-fit radius” – now thats just cheeky. funny though:)

Ah, if this outputs radius values then I shouldn’t have a problem. great!

But before i get that far, I’m attempting to determine diameter values from 2 overlapping circles. I am trying to use BWBOUNDARIES to extract arc values from the areas of the circles that are not overlapping. I then hope to use this circlefit.m to give a diameter estimate of each circle.

Can you help me with extracting the required values from bwboundaries to insert as my input to circlefit.m, if you get my drift? bwboundaries just outputs an array and not the raw data if im correct?

thank you:)

lee

]]>
By: Brett https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-12996 Mon, 19 Jan 2009 16:25:05 +0000 https://blogs.mathworks.com/pick/2008/03/14/fitting-a-circle-easily/#comment-12996 Lee, If I recall my geometry, one would calculate the diameter of the best-fit circle by doubling the best-fit radius. :) (Sorry…couldn’t resist.)

Do note that outputs from this (and, in general, other circle-fitting routines) include the radius of the circle, and the x-y- coordinates of its center.

Once you’ve plotted points in a MATLAB axes, you can save the axes in any of several different formats. Activate the figure, then look at the SAVE AS options from the FILE menu. (These formats include FIG, JPEG, BMP, EPS, PDF, ….)

If you are working from a PLOT in MATLAB, you can always recover the x- and y- data by examining the properties of the children of the axes. In the code above, for instance, you should find 3 children of the main axes. (a = get(gca,’children’). Examine them one by one (get(a(1)), get(a(2)), get(a(3))), and you’ll see that one gives the properties of the rectangle, one gives the properties of the line object that is the center marker, and one gives the properties of the line object (collection of points) that are the plotted x’s and y’s. Among those properties are XDATA and YDATA, from which you can recover the plotted values.

If your question is, if you only have a JPEG (for instance) of a circle, how do you calculate its diameter…that is indeed a different problem–and one for image processing approaches. First, you would have to determine a scale somehow. Then yes, you would likely want to use REGIONPROPS…perhaps after a morphological fill operation?

]]>