从目录 (Python) 导入图像到列表或字典 [英] Importing images from a directory (Python) to list or dictionary
本文介绍了从目录 (Python) 导入图像到列表或字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试导入目录中的所有图像(目录位置已知).
I am trying to import all the images inside a directory (the directory location is known).
path = /home/user/mydirectory
我已经知道一种找出目录长度的方法.
I already know a way of finding out the length of the directory.
我不确定如何将图像(使用 PIL/Pillow
)导入到列表或字典中,以便可以正确操作.
What I'm not sure about is how I can import the images (using PIL/Pillow
) into either a list or a dictionary, so they can be properly manipulated.
推荐答案
我会从使用 glob 开始:
I'd start by using glob:
from PIL import Image
import glob
image_list = []
for filename in glob.glob('yourpath/*.gif'): #assuming gif
im=Image.open(filename)
image_list.append(im)
然后对图像列表 (image_list) 执行您需要执行的操作.
then do what you need to do with your list of images (image_list).
这篇关于从目录 (Python) 导入图像到列表或字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文