Bounding Box largest rectangle?

When I use regionprops BoundingBox, it seems to always capture smaller blobs on the left most side of my image and not my largest blob. How do I bound the box around the largest blob?

4 comentarios

David Young
David Young el 16 de Ag. de 2015
regionprops finds all blobs - there must be something else happening. Please could you post the image and code that demonstrates the problem.
Ivan Q
Ivan Q el 16 de Ag. de 2015
how are all blobs stored in regionprops? How do i choose the largest blob? Here's my code.
diff_im=imsubtract(image(:,:,1),rgb2gray(image));
diff_im-medfilt2(diff_im,[3,3]);
diff_im=im2bw(diff_im, threshold);
diff_im=imfill(diff_im,'holes');
%%find card
[L,num]=bwlabel(diff_im,8);
stats=regionprops(diff_im,'Centroid','Area','BoundingBox');
center=cat(1,stats.Centroid);
area=[stats.Area];
[pixelArea, index]=max(area);
box=stats.BoundingBox;
area=box(3)*box(4);
rectangle('Position',box,'EdgeColor','r');
Walter Roberson
Walter Roberson el 16 de Ag. de 2015
box=stats(index).BoundingBox;
Ivan Q
Ivan Q el 16 de Ag. de 2015
Thanks everyone!

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 16 de Ag. de 2015
stats is a structure array. Each element is a structure and has it's own bounding box. So stats(1).BoundingBox is the bounding box (x,y,width,height) of the first blob. And stats(2).BoundingBox is the bounding box (x,y,width,height) of the second blob, and so on. To display them all:
hold on;
for k = 1 : length(stats) % Loop through all blobs.
% Find the bounding box of each blob.
thisBlobsBoundingBox = stats(k).BoundingBox;
rectangle('Position', thisBlobsBoundingBox);
end

Más respuestas (1)

nilton brites
nilton brites el 21 de Sept. de 2017

0 votos

explain what is definition of bounding box on image?

2 comentarios

Image Analyst
Image Analyst el 21 de Sept. de 2017
It's the box, with edges parallel to the edges of the image, that contains object(s) of interest, such as blobs you got by thresholding. You can have a box around each blob, or around the whole group of them.
Walter Roberson
Walter Roberson el 21 de Sept. de 2017
In particular a bounding box is most often computed as the smallest box with horizontal and vertical sides that encloses the object(s), but bounding boxes can, in general, be larger than that: they are basically a box large enough to be sure you are enclosing the portion of interest.

Iniciar sesión para comentar.

Preguntada:

el 16 de Ag. de 2015

Comentada:

el 21 de Sept. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by