MATLAB: Any way to free hand crop an image

imageimage analysisimage processing

Is there any way to free hand crop on an image? I have an organic shape I want to quickly crop not using the rectangular box that matlab has for cropping. Any way to go about this?

Best Answer

How do you propose cropping a non-rectangular shape? Do you want to zero out parts that aren't within in your "cropped" region. An image always has to be rectangular.
doc imcrop
doc impoly
doc imfreehand
If you want to zero out the parts not in the free hand reason. use the createMask method of the freehand region to build a mask of the free hand region. Then negate it and zero everything in it out.
I = imread('cameraman.tif');
h = imfreehand; %draw something
M = ~h.createMask();
I(M) = 0;