Borrar filtros
Borrar filtros

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

12 visualizaciones (últimos 30 días)
Suhas Yelluru
Suhas Yelluru el 9 de Jul. de 2014
Respondida: Image Analyst el 22 de Ag. de 2022
%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?

Respuestas (2)

Michael scheinfeild
Michael scheinfeild el 9 de Jul. de 2014
inpolygon

Image Analyst
Image Analyst el 22 de Ag. de 2022
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.

Categorías

Más información sobre Images en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by