Cropping an irregular shaped object

5 次查看(过去 30 天)
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.

回答(1 个)

Raunak Gupta
Raunak Gupta 2019-12-6
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.

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by