How to count number of circles of a gray scale image?

I want to count number of circles of a gray scale image. I have attached the sample image. I just want to count the number of circle of that image and fill the gaps of that circle. What should i do??

 Accepted Answer

How many do you see? I see two circular black discs plus a bunch of other blobs that have irregular shapes, though some parts of their perimeters are circular.
Then you can count them with bwlabel();
[~, NumBlobs] = bwlabel(binaryImage);
Another way is to use regionprops() to compute the area and perimeter of the blobs and compute the circularity and keep only blobs that are sufficiently close to being circular.
I can't do it all for you but if you have questions, attach whatever code you have.

4 Comments

Basically i want to fill up those holes of circles and blobs and then i want to detach those blobs and circles using erosion. But when i am using imfill() to fill up those holes it fill up the intersected area of those circles. What should i do?
Here is my code:
if true
I = imread('sample.png');
% figure, imshow(I);title('Main Image');
BW = im2bw(I);
figure, imshow(BW);
BW = imfill(BW,'holes');
figure, imshow(BW);
for n=1:5
BW = bwmorph(BW,'erode');
end;
figure, imshow(BW);title('erode');
end
Split them apart first, then fill.
this post is quite old but ca
n i ask here??
im looking fora solution tom problem but i haven't found it yet
i tried to calculate the circle from the canny result but the results did not match my manualy calculation, the results were too many
this my code
edge_final = handles.edge1;
cla('reset')
imshow(edge_final)
[B,L] = bwboundaries(edge_final,'noholes');
stats = regionprops(L,'All');
bw2 = zeros(size(edge_final,1),size(edge_final,2));
for k = 1:length(B)
boundary = B{k};
delta_sq = diff(boundary).^2;
perimeter = stats(k).Perimeter;
area = stats(k).Area;
metric = 4*pi*area/perimeter^2;
bbox = stats(k).BoundingBox;
eccentricity = stats(k).Eccentricity;
MajorAxisLength = stats(k).MajorAxisLength;
MinorAxisLength = stats(k).MinorAxisLength;
d = MajorAxisLength/MinorAxisLength;
position = [boundary(1,2),boundary(1,1)];
if metric > 0.9
bw2(L==k) = 1;
[handles.D handles.Num_lingkaran]=bwlabel(bw2);
set(handles.text2,'string', handles.Num_lingkaran);
end
end
guidata(hObject, handles);
can you help me to o it?
I'd create your own post for this. Attach your own original input image.
Also explain exactly what "calculate the circle" means because that is very vague and there could be several possible answers for that depending on exactly what that means.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!