MATLAB: Bounding Box largest rectangle

boundingbox regionprops blobImage Processing Toolbox

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?

Best Answer

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
Related Question