Edit-drawing bounding box

1 view (last 30 days)
nkumar
nkumar on 12 Jan 2013
Commented: Mahmoud on 27 Nov 2013
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
Mahmoud
Mahmoud on 27 Nov 2013
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
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
Can you plz tell how to get x and y values of cropped image
Image Analyst
Image Analyst on 19 Jan 2013
Edited: Image Analyst on 19 Jan 2013
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)

Community Treasure Hunt

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

Start Hunting!