Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用imageio从同一目录读取多个图像_Python_Python Imageio - Fatal编程技术网

Python 使用imageio从同一目录读取多个图像

Python 使用imageio从同一目录读取多个图像,python,python-imageio,Python,Python Imageio,我有一个目录test/,里面有图像0.jpg,还有1.jpg。如何使用的mimread函数指定目录test,并读取0和1?或者这不是它的目的 我尝试了imageio.mimread(uri=“/path/to/test/”,format=“.jpg”),但得到了以下结果: --------------------------------------------------------------------------- RuntimeError

我有一个目录
test/
,里面有图像
0.jpg
,还有
1.jpg
。如何使用的
mimread
函数指定目录
test
,并读取
0
1
?或者这不是它的目的

我尝试了
imageio.mimread(uri=“/path/to/test/”,format=“.jpg”)
,但得到了以下结果:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-43-89a6d166a345> in <module>()
----> 1 imageio.mimread(uri="test", format=".jpg", memtest=True)

/Users/myuser/anaconda/envs/python3/lib/python3.5/site-packages/imageio/core/functions.py in mimread(uri, format, memtest, **kwargs)
    279 
    280     # Get reader
--> 281     reader = read(uri, format, 'I', **kwargs)
    282 
    283     # Read

/Users/myuser/anaconda/envs/python3/lib/python3.5/site-packages/imageio/core/functions.py in get_reader(uri, format, mode, **kwargs)
    127 
    128     # Return its reader object
--> 129     return format.get_reader(request)
    130 
    131 

/Users/myuser/anaconda/envs/python3/lib/python3.5/site-packages/imageio/core/format.py in get_reader(self, request)
    165         if select_mode not in self.modes:
    166             raise RuntimeError('Format %s cannot read in mode %r' % 
--> 167                                (self.name, select_mode))
    168         return self.Reader(self, request)
    169 

RuntimeError: Format JPEG-PIL cannot read in mode 'I'
---------------------------------------------------------------------------
运行时错误回溯(上次最近调用)
在()
---->1 imageio.mimread(uri=“test”,format=“.jpg”,memtest=True)
/mimread中的Users/myuser/anaconda/envs/python3/lib/python3.5/site-packages/imageio/core/functions.py(uri、格式、memtest、**kwargs)
279
280#获取阅读器
-->281 reader=read(uri,格式为'I',**kwargs)
282
283读
/get_reader中的Users/myuser/anaconda/envs/python3/lib/python3.5/site-packages/imageio/core/functions.py(uri、格式、模式,**kwargs)
127
128#返回其读卡器对象
-->129返回格式。获取读取器(请求)
130
131
/get_reader中的Users/myuser/anaconda/envs/python3/lib/python3.5/site-packages/imageio/core/format.py(self,request)
165如果选择_模式不在self.modes中:
166 raise RUNTIMERROR('格式%s无法在模式%r'中读取'
-->167(self.name,选择_模式))
168返回self.Reader(self,request)
169
运行时错误:格式JPEG-PIL无法在“I”模式下读取
上面写着:

uri:{str,pathlib.Path,字节,文件}>

要从中加载图像的资源,例如文件名、pathlib.Path、http地址或文件对象,有关详细信息,请参阅文档


尝试
imageio.mimread(uri='test')

我已经查看了imageio的源代码,但是在mimread()中没有看到任何对迭代文件夹中的文件以读取多个图像的支持。我建议改用scikit图像。下面是一个例子:

from skimage.io import imread_collection
seq = imread_collection("*.jpg", conserve_memory=True)
然后,您可以索引到seq以获得每个图像:

seq[0]

seq[1]
等等

或者这不是它的目的

mimread
适用于能够在同一文件中存储多个图像的图像格式。这种格式的一个半流行的例子是
.tiff
,它具有页面的概念,页面可能包含不同的图像。另一个是
.psd
(photoshop格式)

如果要从文件夹中读取图像,可以使用生成器表达式(假设文件夹中仅包含要读取的图像)以传统方式进行读取

(glob.glob(文件夹)中文件名的iio.imread(文件名))
或者,您可以更加复杂,编写一些递归读取和/或根据需要过滤文件的内容

def read_文件夹(文件夹,…):
对于glob.glob(文件夹)中的项目:
如果匹配\u图像\u过滤器(项目):
收益率iio.imread(项目)
elif匹配子文件夹过滤器(项目):
从read_文件夹(项目,…)产生的收益
你明白了;)



注意:这不是我第一次听说
mimread
令人困惑,因此如果您对如何提高清晰度有任何建议,请随时发表评论,我很乐意更新文档。

谢谢,但在我的路径前面添加
uri=
,运气不好。我对问题进行了编辑,以更好地显示我的问题。会发生什么?你有错误吗?请编辑您的问题,并包括我们需要重现您的问题的代码的相关部分。这是否意味着对于使用路径的示例,它将是
seq=imread\u collection(“/path/to/test/*.jpg”,conserve\u memory=True)