MATLAB: Crop an image using coordinate

image processingImage Processing Toolbox

Hi,
How can I crop an image by having the top left coordinate (X1,Y1) and bottom right (X2,Y2).
I2 = imcrop(im,[x1 y1 x2 y2])
does not seem to work?
Thanks

Best Answer

You used 151 instead of 115 in your width. Here, try this:
grayImage = imread('circuit.tif');
subplot(1,2,1);
imshow(grayImage);
h = impixelinfo();
axis on;
I2 = imcrop(grayImage,[115, 89, 161-115,142-89]);
subplot(1,2,2);
imshow(I2)
axis on;