Hi all,
I identified circles and rectangular by a mark circle at centroid. Now I want to count how many object have labeled and how many object not labeled?
The result is in the attached image
Really appreciate for your help
if metric < threshold
centroid = stats(k).Centroid;
plot(centroid(1),centroid(2),'ko');
count =
end

 채택된 답변

Image Analyst
Image Analyst 2022년 4월 16일

1 개 추천

stats = regionprops(L,'Area','Centroid','Perimeter');
allAreas = [stats.Area]
allPerims = [stats.Perimeter];
allCircularities = allPerims .^2 ./ (4 * pi * allAreas)
% Find number with circularity more than 1.5
count = allCircularities > 1.5

댓글 수: 2

Image Analyst
Image Analyst 2022년 4월 16일
For what it's worth, I'm attaching my shape recognition demos.
Tu Nguyen
Tu Nguyen 2022년 4월 16일
I tried your way but all value less than 1.5. Now I am trying both ways to figure out. The method of @Faraz Hedayati I am struggling how to convert the out last output image to an actual image because the spot on the image just a plot.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Tala
Tala 2022년 4월 15일

0 개 추천

I would plot the centroids as filled black circles and threshold colors smaller than 10! then you only have the centorids and length(regionprops( YourImage,'centroid')) would give you the number of rectangulars.

댓글 수: 9

I tried your way but I cant get the answwer. Can you help me more?
clc;
close all;
clear;
I=imread('Shapes_with_holes.png');
bw1 = imbinarize(I);
imshow(bw1)
bw = imfill(bw1,'holes');
bw = bwareaopen(bw,1);
imshow(bw)
[B,L] = bwboundaries(bw,'noholes');
imshow(label2rgb(L,@jet,[.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2),boundary(:,1),'w','LineWidth',2)
end
stats = regionprops(L,'Area','Centroid','Perimeter');
threshold = 1;
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;
metric_string = sprintf('%2.2f',metric);
if metric > threshold
centroid = stats(k).Centroid;
plot(centroid(1),centroid(2),'ko');
end
end
Tala
Tala 2022년 4월 16일
please attach your image with the centroids as black cricles.
Tu Nguyen
Tu Nguyen 2022년 4월 16일
편집: Tu Nguyen 2022년 4월 16일
Yes, sir, I did on my comment below your comment. Or if you want the result, it is here
Tala
Tala 2022년 4월 16일
편집: Tala 2022년 4월 16일
In your original question you highlighted the centroids of rectangulars. In the second image you have the centoirds of circles and rectangulars, and some objects have two centroids.
back to your original question, whatever technique you used yo find the centroid of rectangulars, change your plot option to filled circles to get this (I call this image I):
Ig=rgb2gray(I);
BW=Ig<15;
imshow(BW)
info=regionprops(BW,'Centroid');
length(info)
which spits out 13
Tu Nguyen
Tu Nguyen 2022년 4월 16일
How can I fill black the marked circle?
Image Analyst
Image Analyst 2022년 4월 16일
Not sure what you want. In Faraz's last image the circles were white. If you made them black, the whole image would be black. Or do you want to fill the original image's black dots with the surrounding color, like what you'd to with regionfill()?
Did you see my Answer below?
Tala
Tala 2022년 4월 16일
편집: Tala 2022년 4월 16일
instead of
plot(centroid(1),centroid(2),'ko');
use a dot as your marker with large size.
plot(centroid(1),centroid(2),'.k', 'MarkerSize',25)
Tu Nguyen
Tu Nguyen 2022년 4월 16일
Hi @Faraz Hedayati, how can I process the image with the plot on it? I make the image gray but it backs to initial image without the marked circle
Tala
Tala 2022년 4월 16일
편집: Image Analyst 2022년 4월 16일
I am getting confused about you wanna do after all :).
Did you see Image Analyst's response?
If you want to save your figure as an image you can do:
saveas(gcf,'YourImage.png');
% or
exportgraphics(gcf, 'YourImage.png');
You can then import that as well using
theImage = imread('YourImage.png')

댓글을 달려면 로그인하십시오.

제품

릴리스

R2021b

질문:

2022년 4월 14일

편집:

2022년 4월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by