How do I get only the centroid inside the bounding box?

조회 수: 13 (최근 30일)
Suhas Yelluru
Suhas Yelluru 2014년 7월 9일
답변: Image Analyst 2022년 8월 22일
%compute area centroid and boundingbox
stats = regionprops(bw6, ['basic']);
s = regionprops(bw6, 'centroid');
centroids = cat(1, s.Centroid);
imshow(bw6);
%find size of stats
[N,M] = size(stats);
if (bw==0)
break;
else
tmp = stats(1);
for i = 2 : N
if stats(i).Area > tmp.Area
tmp = stats(i);
end
end
bb = tmp.BoundingBox;
bc = tmp.Centroid;
imshow(data)
hold on
rectangle('Position', bb, 'EdgeColor', 'r', 'LineWidth', 2)
_*plot(centroids(:,1), centroids(:,2), 'b*');*_
hold off
The above code shows all the centroids, however, i want only the centroid that is inside the bounding box. How do i extract the coordinates of only that particular centroid?

답변 (2개)

Michael scheinfeild
Michael scheinfeild 2014년 7월 9일
inpolygon

Image Analyst
Image Analyst 2022년 8월 22일
The centroid of a blob will ALWAYS be inside the bounding box of the blob. How could it not be? Can you think of an example where it's not? No, you can't.
It might not be inside the blob's white pixels, like for the case of a blob shaped like the letter G, or a blob that is a donut shape, but it will always be guaranteed to be inside the bounding box of the blob.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by