detect Circles and squares on the image using regionprops
Show older comments
Now , i have image called "test.png" and my question is how to detect circles with & without holes and display each of them in single figure and here is my code but desn't work with me , so need help
I = imread('test.png');
imshow(I);
I = rgb2gray(I);
I = im2bw(I,0.01);
[L ,num] = bwlabel(I);
stats1 = regionprops (L,'EulerNumber' , 'Area' , 'Perimeter' , 'BoundingBox');
sum = 0;
for R=1:num
% this way desn't work but maybe it just need a little changes
% x = uint8 (stats1(R).BoundingBox(1));
% y = uint8 (stats1(R).BoundingBox(2));
% if (I(x,y) == 0)
% sum = sum + 1;
% bb = stats1(R).BoundingBox;
% rectangle('position',bb,'edgecolor','r','linewidth',1.3);
% end
circularity = (stats1(R).Perimeter .^ 2) ./ (4 * pi * stats1(R).Area);
if (circularity >= 1.1)
sum = sum + 1;
bb = stats1(R).BoundingBox;
rectangle('position',bb,'edgecolor','r','linewidth',1.3);
end
end
disp(sum);
1 Comment
Image Analyst
on 6 Dec 2019

Accepted Answer
More Answers (0)
Categories
Find more on Object Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!