MATLAB Answers

Cropping an irregular shaped object

19 views (last 30 days)
Suchitra Ojha
Suchitra Ojha on 2 Dec 2019
Answered: Raunak Gupta on 6 Dec 2019
Is there any way to crop the irregular shape object so that we can gwt only the pixels of the irregular shaped object?
I have tried imfree hand to get the irregular shaped object,but in this case the remaining pixels of the image are also present with zero values .I dont need the remaining pixels with Nan and zero values.

  0 Comments

Sign in to comment.

Answers (1)

Raunak Gupta
Raunak Gupta on 6 Dec 2019
Hi,
Returning a cropped image will remove the context of information present in the original image while drawing the irregular shape. Currently it is not supported with imfreehand. If it is required to return a cropped image from the image you are currently getting, you may try to remove trailing and leading rows and column with zero value from the image by following the method explained here.
Note the mentioned answer works for grayscale images but If you want to work on color images, I suggest taking average of three channels since the zero values in color image will remain zero here. Applying above method to this 1-channel image will give bounding box which is the effective size of the image that is required. Then imcrop can be used once size of rectangle is extracted on the original image.
Hope this helps.

  0 Comments

Sign in to comment.

Sign in to answer this question.