I have a stack of MRI images that look like 
Screen Shot 2018-11-26 at 12.16.10 AM.png660×624 50 KB

say in shape [train_size, h,w,d]
There is alot of black space making my convolution very heavy so I want to trim the images from the minimum index of the first non-zero pixel value from all the 4 corners. i.e identify the maximum distance I can trim my images from the four corners without losing any non-zero values pixel from any of the images in whole training size. This is only for the height and width. How Could I go about doing this?