Drawing rectangles around binary image objects from region props

Hi, from the binary image above, I've tried drawing boundaries around the object and successfully counted them. But I'm thinking of trying another method which is to use the regionprops to extract information of the location of the blobs. But I do not know how to draw a rectangle around them.
info = regionprops(img2,'Boundingbox')
By using this command, the command windows shows
4×1 struct array with fields:
BoundingBox
Which from what I guess is the total of bounding boxes it found from the image similar to the boundary way that I used. Can I use this information and draw a rectangle for the images and and display it in my source image?

 採用された回答

KSSV
KSSV 2018 年 7 月 12 日

2 投票

info = regionprops(img2,'Boundingbox') ;
imshow(img2)
hold on
for k = 1 : length(info)
BB = info(k).BoundingBox;
rectangle('Position', [BB(1),BB(2),BB(3),BB(4)],'EdgeColor','r','LineWidth',2) ;
end

6 件のコメント

Adrian Lim
Adrian Lim 2018 年 7 月 12 日
From what I understand, the BB1 to BB4 is the number of boxes exist right? What if there are three or six boxes. Because it's an analysis and it has to be automated so the program can run on its own.
KSSV
KSSV 2018 年 7 月 12 日
BB will be having four values, first two points corresponds to (x,y) coordinates of left bottom corner of the rectangle, third is width and fourth is height of the rectangle. The code is already automates, it will count the number of boxes and plot.
Adrian Lim
Adrian Lim 2018 年 7 月 12 日
Oh. Looks like i misunderstood the line. Thank you so much for explaining!
Nilesh Mudgal
Nilesh Mudgal 2019 年 5 月 16 日
編集済み: madhan ravi 2019 年 5 月 16 日
how to remove the unwanted blobs which have been produced due to shadow or reflection. It creating a huge number of blobs in my image even if there ie negligible amount of shadow or relflection or may be some other noise. i want to remobe these first and then find the blobs. Also i am converting th image to binary using graythresh value.
Adam Campos
Adam Campos 2023 年 3 月 7 日
Thank you @KSSV, that is what I had been looking for. Is this in the Matlab documentation somewhere?

サインインしてコメントする。

その他の回答 (1 件)

smitha suresh
smitha suresh 2021 年 2 月 22 日

0 投票

how to draw seperate bounding boxes for meged objects

1 件のコメント

Walter Roberson
Walter Roberson 2021 年 2 月 22 日
How are the merged objects represented? Have you already detected them separately?
For example if the input were
|---|
| |__
|___| |
|___|
then have you already broken that apart into two rectangles, or do you still need to figure out how to break them up?
If you have already broken them up, then when you draw the bounding boxes, do you want all of the edges shown (perhaps rectangles of different colors) or only exterior edges like
|---|
| |__
|__ |
|___|

サインインしてコメントする。

製品

リリース

R2017a

質問済み:

2018 年 7 月 12 日

コメント済み:

2023 年 3 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by