Edit-drawing bounding box

조회 수: 2 (최근 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개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by