arnavlohe15
arnavlohe15

Reputation: 334

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 i.e. 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?

Upvotes: 3

Views: 741

Answers (1)

pangyuteng
pangyuteng

Reputation: 1839

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") 

Upvotes: 3

Related Questions