【问题标题】:my picture won't resize tf.image.resize_with_padding tensorflow我的图片不会调整 tf.image.resize_with_padding tensorflow
【发布时间】:2020-05-26 20:57:19
【问题描述】:

我的原始图像是 600*600 像素,我想将其调整为 300*300 像素

调整代码大小

import tensorflow as tf
import numpy as np
from tensorflow.keras.preprocessing.image import array_to_img
from tensorflow_core.python.keras.layers.image_preprocessing import ResizeMethod


def resize(image, w=300, h=300):

    image = tf.convert_to_tensor(np.asarray(image))
    size = (w, h)
    tf.image.resize_with_pad(
        image,
        h,
        w,
        method=ResizeMethod.BILINEAR
    )
    image = array_to_img(image)
    return image

保存图片后尺寸不变

保存图片代码

def write_images(images, path):
    try:
        index = 1
        for img in images:
            img.save(path+f'/{index}.jpeg')
            index += 1
    except:
        print('Error while writing images')

【问题讨论】:

    标签: python python-3.x image tensorflow image-processing


    【解决方案1】:

    Tensorflow 操作不到位。您需要将调整大小操作的结果分配如下:

    image = tf.image.resize_with_pad(
        image,
        h,
        w,
        method=ResizeMethod.BILINEAR
    )
    

    【讨论】:

    • 所以每个 tf.image.* 返回值并且不更新图像本身?
    猜你喜欢
    • 2021-07-02
    • 2015-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    相关资源
    最近更新 更多