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

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Felix
on 18 Sep 2013

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

st = regionprops(BW, 'BoundingBox' );

figure, imshow('MY_IMAGE.jpg')

rectangle('Position',[st.BoundingBox(1),st.BoundingBox(2),st.BoundingBox(3),st.BoundingBox(4)],... '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

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 ) end

Show 3 older comments

Image Analyst
on 19 Jan 2014

Can you start your own thread so you'll get emails about updates instead of Felix?

Explorer
on 19 Jan 2014

## 0 Comments