MATLAB: Circle fitting

circle fittingcurve fittingimage processing

I have a binary image. This image contains white points randomly a ranged inside a region of interest. I want to draw a circle that can include all these points inside it. Means that I want to write a code that detect all these active points automatically and draw a circle in such a way that all the active (white) points come inside this circle. And outer most white point become a part of the boundary of circle. Can anyone help me in that?

Best Answer

regionprops() the binary image, asking for Centroid and ConvexHull.
The center of the circle will be the centroid.
The ConvexHull will be an N x 2 array of x+y points. The point in that list that is furthest from the centroid will be the point that must be passed through; i.e., that maximum distances will be the radius of the circle.
You could also use the PixelIDList instead of the ConvexHull; it just gives you more points whose distance would have to be calculated.
Related Question