从目录导入图像(Python) [英] Importing images from a directory (Python)

查看:81
本文介绍了从目录导入图像(Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以导入目录中的所有图像(目录位置已知).
我已经找到一种找出目录长度的方法.
我不确定的是如何将图像(使用PIL/Pillow)导入列表或字典中.

Is there any way to import all the images inside a directory (the directory location is known).
I have already found a way of finding out the length of the directory.
What I'm not sure about is how I can import the images (using PIL/Pillow) into either a list or a dictionary.

推荐答案

我将从使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆