如何从多个文件夹中读取图像? [英] How to read Images from multiple folders?

查看:117
本文介绍了如何从多个文件夹中读取图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理乳房X射线照片.我有3个文件夹,每个文件夹包含40张图像.我想从每个文件夹中读取图像,以便可以从每个图像中提取特征并将其存储在变量中.

I am working with mammogram images. I have 3 folders with each folder consisting of 40 images. I want to read images from each folders so that I can extract features from each of the image and store them in a variable.

我不知道如何从多个文件夹中读取图像.如果有人可以帮助我,这将真的很有帮助.

I don't know as how can I read images from multiple folders. It would be really helpful if anyone can help me with this.

推荐答案

使用os.walk递归遍历目录,并使用PIL处理图像.

Use os.walk to recursively traverse a directory, and PIL to handle images.

import os
from PIL import Image

for path, _, files in os.walk('.')
    for file in files:
        foo = Image.open(file) 
        # now do something with the image

这篇关于如何从多个文件夹中读取图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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