MATLAB: Regarding cropping a polygon out of an image

impoly

hi folks can anybody help me with cropping a polygon out of the image?
i used the following code
I=dicomread('100.ima');
figure,imshow(I,[]);
h=impoly;
position=wait(h);
its providing the option for configuring the required polygon.i have also said it to copy figure.
how can i see only the cropped image?
can anyone help with imcrop()to see the output

Best Answer

Do not use
imshow(x(~bw), []);
but
imshow(x, []);
"x(~bw)" is a vector and IMSHOW must fail.
What is the problem with the 2nd part of your program? If you just want to apply the IMCROP once, use something like "if z==1".