【问题标题】:Convert an image into matrix of specific dimensions?将图像转换为特定尺寸的矩阵?
【发布时间】:2020-06-19 07:42:48
【问题描述】:

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

我有一组不同大小的图像。而且我需要它们都在一个 50 X 50 矩阵中。

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

如果可以,那我该怎么做呢?

【问题讨论】:

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


【解决方案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) 的图像作为数组!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 2018-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多