简体   繁体   中英

Tensorflow tf.image.resize_image_with_crop_or_pad For 3D Images

I want to train a convolutional neural network on 3 dimensional nifti images ie they have a width, height, and depth. A sample shape is (166, 256, 256). However, I have read that when implementing fully connected layers, you need to have all the images of the same size. The first dimension is one of 160,166,170, the second and third dimensions are one of 240,256,192. I want to pad all images to (170, 256, 256) so I do not lose any information, but the

tf.image.resize_image_with_crop_or_pad

function only seems to have arguments for two functions. How can I go about padding these images?

i think your best bet is tf.pad , below code was not tested.

target_z = 170
# x is shape of (166, 256, 256)
zp = 170-x.get_shape().as_list()[0]
# what if zp is negative ?
paddings = tf.constant([[0, zp], [0, 0], [0,0]])
tf.pad(x, paddings, "CONSTANT") 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM