【发布时间】: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