# Imfindcircles detecting massiveness?

1 view (last 30 days)
Wasgeht Siedasan on 17 Sep 2020
Hello,
I was using the code output from the image segmenter App in matlab to build a function that recognizes circles, cuts them out and accumualtes them on a new picture.
Input:
Code:
figure;
subplot(1,2,1),
imshow(BW1);
title('original')
Rmin = 22;
Rmax = 65;
% Find circles
[centersBright, radiiBright] = imfindcircles(BW1,[Rmin Rmax],'ObjectPolarity','bright','Sensitivity',0.90, 'EdgeThreshold',0.1);
BW = false(size(BW1,1),size(BW1,2));
[Xgrid,Ygrid] = meshgrid(1:size(BW,2),1:size(BW,1));
[m,n] = size(centersBright);
for x = 1:m
BW = BW | (hypot(Xgrid-centersBright(x,1),Ygrid-centersBright(x,2)) <= radiiBright(x));
end
%change picture format to create masked image
uint8Image = uint8(255 * BW1);
thresh = multithresh(uint8Image,3);
seg_I = imquantize(uint8Image,thresh);
RGB = label2rgb(seg_I);
% % % Create masked image.
subplot(1,2,2),
Output
Now, I want to increase sensitivity to find more circles, but it starts pickung up a lot of junk aswell.
I would like to include an IF statement in the for-loop that only lets circles pass that are at least 70% filled out or so, so not too much junk gets through. How could I do that? I don't think imfindcicrles has an output that would help here. I'd need the number of white vs black pixels in the circle somehow, aka the massiveness of the detected circle.
Also, the image segmenter app does not take binary, only RGB or grayscale, so I had to also cheat a little bit with the image conversions in the middle of the code there so the repmat would do it's job, is there some way to adjust the repmat to make tha tunnecessary?
Thanks in advance for the help!

Madhav Thakker on 22 Sep 2020
Hi Wasgeht,
I understand that you want to only retain those circles which have more than 70% of pixels that are white. One of the possible ways is to go through each circle and count the number of white pixels in the circle. You can use inpolygon for checking whether a query point lies in the polygon or not. You can use polyshape to create a polygon for each circle using centre and radius.
Here is another answer which does a similar thing.
Hope this helps.

R2020a

### Community Treasure Hunt

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

Start Hunting!