# Circle fitting for a binary image

I a new to MATLAB and i am trying to apply circle fitting technique to the following image.

Image

Expected Output

I used the following code with no luck:

[centers, radii] = imfindcircles(W,[30 65],'ObjectPolarity','bright');


Note that the circle size can vary between picture

Any suggestions.

imfindcircles can take in other "Name, Value" pairs as parameters. In your case, a really helpful one is the Sensitivity parameter. I would change your first line to include this (also note that 'bright' is the default value for 'ObjectPolarity', so I took it out). The value 0.95' here can be tuned to get more or fewer circles identified.

[centers, radii] = imfindcircles(W, [30 65], 'Sensitivity', 0.95);`

Since you mentioned circles may vary between pictures, it would be beneficial use some other parameters to get better results across the set of images. Check out the MATLAB documentation online for specifics.

• i doesn't work also. Circles are not shown in the figure – Hadi Dec 31 '17 at 8:31
• Well, for different images you will have to change that parameter to get the result you want. I gave 0.95 here just as an example, but running a quick script on MATLAB it seems like Sensitivity of 0.96 actually gives better results. So try replacing the 0.95 with 0.96 instead. – goldrik Dec 31 '17 at 9:42
• now it is working – Hadi Dec 31 '17 at 9:54