Fitting a circle of known radius to a binary image

I have some binary images to which I would like fit the largest possible circle.
The method I am currently thinking of using is finding the maximum radius using regionprops and fitting that max radius circle to the boundary pixels of the blobs (bwboundaries) (see picture below). I cannot use Hough as the circle all have different radius and often leads to a very noisy output. I have also tried using a least squares algorithm with no radial constraint, but the radius outputted is often to small.
Could someone help me implement something like this, but for matlab, point me to a suitable algorithm or give any better suggestions?
Many thanks :)

 Akzeptierte Antwort

Image Analyst
Image Analyst am 15 Mär. 2020
You can simply measure all the areas and equivalent circular diameters and you're pretty much done.
props = regionprops(mask, 'Area', 'EquivDiameter');
allAreas = [props.Area]
allDiameters = [props.EquivDiameter]
[largestArea, indexOfLargestArea] = max(allAreas)
largestDiameter = allDiameters(indexOfLargestArea)
The equivalent circular diameter is the diameter your blob would have as if all the pixels were rearranged into a perfectly circular shapte.

4 Kommentare

Thanks for your answer. This can be used to find the maximum diameter of the blobs, however, I essentially need to find the centre of circle if the curved edge of the blob continued all the way around as shown below in red. This is quite a bad image, but hopefully you get the idea. The red markings are the circle I would like to be found by using the max diameter with your method. I would then like to find the centre of mass of the circle (represented byt the blue point). The black line is what tends to be outputted by the least squares circle fit algorithms giving an inaccurate centre of mass. I hope this makes a bit more sense as to what I am trying to do. Many thanks :)
This is a copy of the image, which might help:
You might want to look at this:
Pass all the points from your blob into that function to get the outermost circle that will contain everything. But what if you have just some irregularly shaped blob, not like a perfect hemicircle or full circle? What if is just looks like an amorphous blob or splat? What outline would you want to use? Why not use the fitted circle? Or the convex hull? Do you know for a fact that your original objects are circles that have had a chord clipped off of them?
Thats exactly what I was looking for thank you so much :).
For anyone else this is the function i ended up using:

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by