Edit-drawing bounding box

1 visualización (últimos 30 días)
nkumar
nkumar el 12 de En. de 2013
Comentada: Mahmoud el 27 de Nov. de 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 comentario
Mahmoud
Mahmoud el 27 de Nov. de 2013
rectangle('Position',st.BoundingBox,'EdgeColor','r','LineWidth',3 )

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 18 de En. de 2013
Editada: Image Analyst el 18 de En. de 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 comentarios
nkumar
nkumar el 19 de En. de 2013
Can you plz tell how to get x and y values of cropped image
Image Analyst
Image Analyst el 19 de En. de 2013
Editada: Image Analyst el 19 de En. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by