将图像转换为特定尺寸的矩阵?

时间:2020-03-06 14:40:02

标签: python-3.x matplotlib image-processing matrix

是否可以在python中将图像转换为特定尺寸的数组?

我有一组不同大小的图像。而且我需要它们全部精确地放在50 X 50的矩阵中。

是否可以通过matplotlib读取图像,然后将该阵列转换为50 X 50的阵列?

如果可能的话,我该怎么办?

1 个答案:

答案 0 :(得分:1)

使用Pillow库是您想要的。

from PIL import Image
image_paths = ["image1.jpg", "image2.jpg"]
arrays = list()

for image_path in image_paths:
    img = Image.open(image_path)
    img.thumbnail(size=(50, 50))
    img_as_array = np.array(img)
    arrays.append(img_as_array)

现在arrays包含将您的图片大小调整为(50,50)作为数组!