使用Python在数组中储存图像

2024-04-19 16:31:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要读取图像(500x300x3)并将其存储在数组中:

import os
import numpy as np

data = np.empty((number_of_images, 3, 300, 500), dtype="float32")

imgs = os.listdir("./images")
num = len(imgs)
for i in range(num):
    img = Image.open("./images/" + imgs[i])
    arr = np.asarray(img, dtype="float32")
    data[i, :, :, :] = arr

现在发生错误,因为arr的大小是500x300x3,但是我想将它存储为np.empty((number_of_images, 3, 300, 500), dtype="float32")。在

如有任何建议,我们将不胜感激!在


Tags: of图像importnumberimgdataosnp