MATLAB: Edit-drawing bounding box

bounding boxImage Processing Toolbox

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

Best Answer

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.