Bounding block using MATLAB for image

I am trying to draw a frame around a white blob in the image below:

enter image description here

I like it:

bw = imread('box.jpg');
bw=im2bw(bw);
imshow(bw)
L = bwlabel(bw);
s = regionprops(L, 'Area', 'BoundingBox');
s(1);
area_values = [s.Area];
idx = find((100 <= area_values) & (area_values <= 1000)); % list of all the objects   

%whose area is between 100 and 1000

bw2 = ismember(L, idx); %construct a binary image containing all the objects whose 

%area is between 100 and 1000 by passing L and idx to ismember. 

imshow(bw2)

Bw2 output so far: enter image description here

Will someone tell me how to draw a bounding box around this blob (white)?

Update Answer Waji actually exactly solved the problem.

+3
source share
4 answers

Pseduo -

  • Choose the largest y, the largest x, the smallest x, the smallest y in the blob. That is, the points on the blob. These are your coordinates that you can use to create a bounding box.

Assuming the top left corner of the image is (0,0)

(smallestX,smallestY)-----------------(largestX,smallestY)    
      |                                      |
      |                                      |          
      |                                      | 
      |                                      |
(smallestX,largestY)------------------(largestX,largestY)    

And to find the minimum / maximum values ​​and indices.

[r,c]=find(img==min(min(img)))
[r,c]=find(img==max(max(img)))

r, c img.

  • , .
  • , . MakredZoomed
+3

20 000- , , , , .

, . s(idx).BoundingBox

, script:

bb = s(idx).BoundingBox;
rectangle('Position',[bb(1) bb(2) bb(3) bb(4)],'EdgeColor','green');

:

enter image description here

+3

regionprops Image Toolbox?

+2

I think you can try using bwboundries

boundaries = bwboundaries(blob);

numberOfBoundaries = size(boundaries);

for k = 1 : numberOfBoundaries

    thisBoundary = boundaries{k};

    plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);

end
0
source

All Articles