I need to resize some 3D data, like in the tf.image.resize_images
method for 2d data.
I was thinking I could try and run tf.image.resize_images
My approach to this would be to resize the image along two axis, in the code I paste below, I resample along depth and then width
def resize_by_axis(image, dim_1, dim_2, ax, is_grayscale):
resized_list = []
if is_grayscale:
unstack_img_depth_list = [tf.expand_dims(x,2) for x in tf.unstack(image, axis = ax)]
for i in unstack_img_depth_list:
resized_list.append(tf.image.resize_images(i, [dim_1, dim_2],method=0))
stack_img = tf.squeeze(tf.stack(resized_list, axis=ax))
print(stack_img.get_shape())
else:
unstack_img_depth_list = tf.unstack(image, axis = ax)
for i in unstack_img_depth_list:
resized_list.append(tf.image.resize_images(i, [dim_1, dim_2],method=0))
stack_img = tf.stack(resized_list, axis=ax)
return stack_img
resized_along_depth = resize_by_axis(x,50,60,2, True)
resized_along_width = resize_by_axis(resized_along_depth,50,70,1,True)
Where x will be the 3-d tensor either grayscale or RGB; resized_along_width is the final resized tensor. Here we want to resize the 3-d image to dimensions of (50,60,70)