MATLAB: Cropping a particular object in an image

cropcroppingdigital image processingimageimage analysisimage processingobject

Hello,
I need to crop a specific object from an image, I have the object annotated and I also have the pixels of the boundaries of the object. Now I want to crop that particular object and nothing else. Please help me out.
Thanks.

Best Answer

You said you " have the pixels of the boundaries of the object", so simply use them as indexes:
croppedImage = originalImage(row1:row2, col1:col2); % Gray scale.
croppedImage = originalImage(row1:row2, col1:col2, :); % If color RGB image.