如何将包含图像的文件加载到python数组中?

时间:2018-07-23 03:06:39

标签: python pandas image-processing

有没有一种方法可以使用pandas库将图像(作为像素化数据)简单地加载到单个数组中?

1 个答案:

答案 0 :(得分:1)

假设您有一个仅包含JPEG图像的文件夹。

首先,导入所需的一切

man column

然后,设置仅包含图像的文件夹的位置。使用此文件夹位置,我们将为每个图像生成完整文件名列表。

from os import listdir
from os.path import isfile, join
import imageio

然后,您可以启动一个空列表,开始一次打开一个文件并将其附加到列表中。

image_folder_path = "D:\\temp\\images"

onlyfiles = [f for f in listdir(image_folder_path) if isfile(join(image_folder_path, f))]

full_filenames = [join(image_folder_path,this_image) for this_image in onlyfiles]

现在,变量image_list = [] for this_filename in full_filenames: image_rgb_values = imageio.imread(this_filename) image_list.append(image_rgb_values.copy()) image_list = np.array(image_list) 已存储了所有图像。

如果所有图像的尺寸都相同(宽度x高度),这将是最好的选择,但否则应该也可以使用。

希望有帮助! =)