# count rectangular and circles

14 Ansichten (letzte 30 Tage)
Tu Nguyen am 14 Apr. 2022
Kommentiert: DGM am 15 Apr. 2022
Hi all,
I want to count how many rectangular and circles in the image? what is the difference between rectagular and circle in matlab regionprops?
Also, I want to count how many rectangular and circles, both with holes in the image?
Finally, I want to export a figure just square and rectangular only.
clc;
close all;
clear;
A = imbinarize(A);
[label counts]= bwlabel(A);
imshow(A);
stats = regionprops(A,'Circularity','Centroid','Area','Perimeter','Solidity','FilledArea');
filledImage = imfill(A,'holes');
boundaries = bwboundaries(filledImage);
circularity = [stats.Circularity];
perimeters = [stats.Perimeter];
area = [stats.Area];
filledarea = [stats.FilledArea];
solidities = [stats.Solidity];
Centroid = [stats.Centroid];
circularities = perimeters.^2./(4*pi*filledarea);
hold on;
for blobNumber = 1 : counts
if circularities(blobNumber) < 1.19
theLabel = 'Circle';
elseif circularities(blobNumber) < 1.53
theLabel = 'Rectangle';
else
theLabel = 'Triangle';
end
text(stats(blobNumber).Centroid(1), stats(blobNumber).Centroid(2),...
theLabel, 'Color', 'r');
end
##### 3 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Tu Nguyen am 14 Apr. 2022
I read the answer, however, they use a function minboundrect that is the built-in function. Do you have any method that classify rectangular and circles ny metric value?
DGM am 15 Apr. 2022

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

yanqi liu am 15 Apr. 2022
yes，sir，use regionpropers to find difference between rectagular and circle, may be use：
Circularity、BoundingBox
such as
bwi = imcrop(bw, round(stats(i).BoundingBox));
rate = nueml(find(bwi(:)))/numel(bwi);
now we can find rectagular get more rate than circle, may be try it.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Region and Image Properties finden Sie in Help Center und File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by