Merge pull request #1440 from blink1073/fix-imread

Fix handling of ImageCollection indexing and add test
This commit is contained in:
Juan Nunez-Iglesias
2015-03-25 14:20:17 +11:00
2 changed files with 23 additions and 6 deletions
+10 -6
View File
@@ -135,7 +135,8 @@ class ImageCollection(object):
ic = ImageCollection('/tmp/*.png', load_func=imread_convert)
For files with multiple images, the images will be flattened into a list
and added to the list of available images.
and added to the list of available images. In this case, ``load_func``
should accept the keyword argument ``img_num``.
Examples
--------
@@ -165,7 +166,7 @@ class ImageCollection(object):
self._numframes = self._find_images()
else:
self._files = load_pattern
self._numframes = len(load_pattern)
self._numframes = len(self._files)
self._frame_index = None
if conserve_memory:
@@ -254,13 +255,16 @@ class ImageCollection(object):
if ((self.conserve_memory and n != self._cached) or
(self.data[idx] is None)):
kwargs = self.load_func_kwargs
if self._frame_index:
fname, img_num = self._frame_index[n]
self.data[idx] = self.load_func(fname, img_num=img_num,
**self.load_func_kwargs)
if img_num > 0:
self.data[idx] = self.load_func(fname, img_num=img_num,
**kwargs)
else:
self.data[idx] = self.load_func(fname, **kwargs)
else:
self.data[idx] = self.load_func(self.files[n],
**self.load_func_kwargs)
self.data[idx] = self.load_func(self.files[n], **kwargs)
self._cached = n
return self.data[idx]
+13
View File
@@ -1,6 +1,7 @@
import os
import skimage as si
import skimage.io as sio
from skimage import data_dir
import numpy as np
from numpy.testing import *
@@ -112,5 +113,17 @@ def test_metadata():
assert meta[1][('EXIF_MAIN', 'Software')].startswith('I')
@skipif(not FI_available)
def test_collection():
pattern = [os.path.join(data_dir, pic)
for pic in ['camera.png', 'color.png', 'multipage.tif']]
images = sio.ImageCollection(pattern[:-1])
assert len(images) == 2
assert len(images[:]) == 2
images = sio.ImageCollection(pattern)
assert len(images) == 3
assert len(images[:]) == 3
if __name__ == "__main__":
run_module_suite()