Edit-drawing bounding box

I have an Image ,and i have cropped the mouth part,so the
command is
I1=I(172:228,82:179);
for this image i have done morphological operation such as dilation ,erosion,removing boundary components and for this image for drawing rectangle
st = regionprops(X, 'BoundingBox' );
imshow(X)
rectangle('Position',[st.BoundingBox(1),st.BoundingBox(2),st.BoundingBox(3),st.BoundingBox(4)],'EdgeColor','r','LineWidth',3 )
where X is the image after process
i got rectangle box as shown, now i tried to draw rectangle box over mouth portion X over the original image, but it is not in exact mouth are ,it was in left corner, plz assist how to draw in exact mouth part of original Image for the coordinates of X

1 Comment

rectangle('Position',st.BoundingBox,'EdgeColor','r','LineWidth',3 )

Sign in to comment.

 Accepted Answer

Image Analyst
Image Analyst on 18 Jan 2013
Edited: Image Analyst on 18 Jan 2013

0 votes

The problem is you cropped the image so that the bounding box coordinates are with respect to the much smaller I1 image, but then when you go to display it, you're displaying it over (the badly named) X (which I assume is the same as the also-badly-named I) rather than I1.

4 Comments

nkumar
nkumar on 19 Jan 2013
Edited: nkumar on 19 Jan 2013
ok then please tell how to solve it
Image Analyst
Image Analyst on 19 Jan 2013
Edited: Image Analyst on 19 Jan 2013
You need to add the x and y of the cropping rectangle used in your call to get I1 to the x and y used in your call to rectangle().
Can you plz tell how to get x and y values of cropped image
You see where you did this:
I1=I(172:228,82:179);
? Well now when you're doing your call to rectangle, if you pass in x = st.BoundingBox(1) if that is 1 it will put it at 1 of your original image, not at 82. So you need to add 81 to st.BoundingBox(1) to get it to show up at column 82 instead of column 1 of your original image. So you call or rectangle should be
xOnOriginal = 81 + st.BoundingBox(1);
yOnOriginal = 171 + st.BoundingBox(1);
rectangle('Position',[xOnOriginal, yOnOriginal, st.BoundingBox(3), st.BoundingBox(4)], 'EdgeColor', 'r', 'LineWidth', 3);
Remember not to get confused with row,column versus x,y. A lot of functions take x,y and that would be column, row not row, column. Conversely matrices take row,column and that would be y,x not x,y.

Sign in to comment.

More Answers (0)

Asked:

on 12 Jan 2013

Commented:

on 27 Nov 2013

Community Treasure Hunt

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

Start Hunting!