Resize 3D data in tensorflow like tf.image.resize_images

后端 未结 2 822
旧时难觅i
旧时难觅i 2021-02-09 19:23

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

2条回答
  •  甜味超标
    2021-02-09 19:47

    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)

提交回复
热议问题