MATLAB Answers


Rectangle around the object, Bounding box,

Asked by Felix
on 18 Sep 2013
Latest activity Commented on by syhem samti
on 19 Nov 2015

Hello, I used this code to make rectangle around the object at binary image:

st = regionprops(BW, 'BoundingBox' );

figure, imshow('MY_IMAGE.jpg')

'EdgeColor','r','LineWidth',2 )

but if I have more than one object, this code doesn't working How can I draw N rectangles for N objects on image? Thank you


1 Answer

Answer by Image Analyst
on 18 Sep 2013
 Accepted answer

Put it in a loop (untested)

for k = 1 : length(st)
  thisBB = st(k).BoundingBox;
  rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
  'EdgeColor','r','LineWidth',2 )


on 19 Jan 2014


does it work the same way as "vision.BlobAnalysis"? same results?

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!