Edit-drawing bounding box

1 次查看(过去 30 天)
nkumar
nkumar 2013-1-12
评论: Mahmoud 2013-11-27
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 个评论
Mahmoud
Mahmoud 2013-11-27
rectangle('Position',st.BoundingBox,'EdgeColor','r','LineWidth',3 )

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2013-1-18
编辑:Image Analyst 2013-1-18
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 个评论
nkumar
nkumar 2013-1-19
Can you plz tell how to get x and y values of cropped image
Image Analyst
Image Analyst 2013-1-19
编辑:Image Analyst 2013-1-19
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Segmentation and Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by