我正在尝试使用skimage.io.imread_collection从存档中读取多个图像,但出于某种原因会抛出错误:
"没有名为' 00071198d059ba7f5914a526d124d28e6d010c92466da21d4a04cd5413362552 /掩码/ * .png'在档案馆"。
我多次检查过,这样的目录存在于存档中,并且使用* .png我只是指定我希望我的集合中包含所有图像,imread_collection
运行正常,当我尝试下载的图像不是来自存档,但来自解压缩的文件夹。
#specify folder name
each_img_idx = '00071198d059ba7f5914a526d124d28e6d010c92466da21d4a04cd5413362552'
with zipfile.ZipFile('stage1_train.zip') as archive:
mask_ = skimage.io.imread_collection(archive.open(str(each_img_idx) + '/masks/*.png')).concatenate()
可能有人解释我,发生了什么?
答案 0 :(得分:1)
Not all scikit-image plugins support reading from bytes, so I recommend using imageio
. You'll also have to tell ImageCollection how to access the images inside the archive, which is done using a customized load_func
:
from skimage import io
import imageio
archive = zipfile.ZipFile('foo.zip')
images = [f.filename for f in zf.filelist]
def zip_imread(fn):
return imageio.imread(archive.read(fn))
ic = io.ImageCollection(images, load_func=zip_imread)
ImageCollection has some benefits like not loading all images into memory at the same time. But if you simply want a long list of NumPy arrays, you can do:
collection = [imageio.imread(zf.read(f)) for f in zf.filelist]