MATLAB: Use ginput to crop an image

binarycropginputimageimshow

k

Best Answer

You need to define Rect to use the ginput points.
I = imread("image.jpeg") ;
imshow(I) ;
[Px,Py] = ginput(2) ;
Px = round(Px) ; Py = round(Py) ;
R = [Px(1) Py(1) Px(2)-Px(1) Py(2)-Py(1)] ; %[ x y W H]
I1 = imcrop(I,R) ;
figure
imshow(I1)
Play around with creating R...I am not sure whether they are correct here.
NOTE: While using imcrop also you do the same, select left top first and then bottom right. You define a rectangle.
Related Question