Crop Border of 3D "Images"

I wrote “Images” because what I have aren’t actual images but more a simulated 3D field that can be viewed as image.

What I want to achieve is to remove the empty boarder around these images (value 0) to reduce the number of pixels or to be exact features as these will be used for machine learning (CNN). Note that my values can also be negative or if I rescale zeroes will not be 0 anymore.

Therefore Auto-crop seems to do exactly the opposite of what I want. I want to enforce exclusion of certain values not enforce inclusion. Also the cropping would then need to be applied to the test set.

Is this possible at all with image processing? Or do I need to drop down to do it manually / programmatically?

Hi @beginner,
This could be doable with image processing, I just need some more information to figure it out.

  • Do you want to exclude only the 0 values? E.g. crop the image to the smallest bounding box that contains all non-zero valued pixels?
  • You could try experimenting with the Image Calculator node, it lets you perform mathematical operations on pixels. You could try setting all zero pixels to a large negative value, setting a larger value as minimum in the Auto Crop node and after the croping setting all pixels with that value back to zero.


Setting 0 values to very low value makes sense and then crop. But I just realized Auto-crop is applied per image. I will want to keep the image the same size for all images and only crop as far that the “largest” one in each dimension still fits.
(Or said otherwise pixels of different images that overlap before cropping should still overlap after)

As an extreme example if I have a 100x100 image and all except 1 image only use the 10 left most columns and the 1 exception image only uses 1 pixel, the lower right one, nothing can be cropped. (in reality this would probably be noise and best removed but just to explain what I mean).

Or is a CNN smart enough to ditch the empty border pixels while only having a minor impact on performance?

This depends on your data and your usecase, you might try some size augmentation (scale the images smaller (w/ padding) and larger (w/ cropping)) to make the CNN sensitive to differently sized targets, if the amount of empty border varies greatly between your input “images”.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.