MATLAB: Crop an image using multiple coordinates

croppinggetpositionimcropimfreehandMATLAB

I used the "imfreehand" to crop an irregular shape and save its positions into a variable. This position variable is a 85*2 double matrix (85 points, X and Y coordinates). Now, I want to use the same position to crop another image (different layer of the image, but the location of the objects is the same). The functions I can find all requires rectangle positions (X1,X2,Y1,Y2). In my situation, I have 82 different (X,Y) coordinates, how can I use the position information to crop a new image?

Best Answer

You should save the original imfreehand object, h.
h=imfreehand(_____)
Then you can just do
cropped = double(AnotherImage).*h.createMask