我使用了一个图像数据集进行机器学习训练。每个图像都有64px的宽度和64px的高度。现在,我想使用来自google的图像来测试我的机器学习模型。问题是google图像比训练图像大,我想调整它们的大小,使它们的高度和宽度为64px (就像训练集中的图像一样)。在python中有什么方法可以做到这一点吗?我确实找到了一些方法,但它们都保持纵横比。因此,我无法实现64 * 64大小。
发布于 2020-02-28 03:04:24
我在PIL中找到了调整图像大小但不保持纵横比的函数。
from PIL import Image
image = Image.open('./dataset/image.jpeg')
image= image.resize((64,64))发布于 2020-02-28 03:09:38
您可以使用python-resize-image。
安装程序包:
pip install python-resize-image示例:
from PIL import Image
from resizeimage import resizeimage
#open image file
with open('image.jpg', 'r+b') as fd_img:
# create a PIL Image from file
img = Image.open(fd_img)
# resize image (contain)
img = resizeimage.resize_contain(img, [64, 64])
# covert to RBA incase it's RGBA
img = img.convert("RGB")
# save image
img.save('resized-image.jpg', img.format)https://stackoverflow.com/questions/60439843
复制相似问题