Drawing rectangles around binary image objects from region props

조회 수: 16 (최근 30일)
Adrian Lim
Adrian Lim 2018년 7월 12일
댓글: Adam Campos 2023년 3월 7일
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일
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
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일
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

Community Treasure Hunt

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

Start Hunting!

Translated by