diff --git a/skimage/io/_plugins/pil_plugin.py b/skimage/io/_plugins/pil_plugin.py index f8d6488d..92482b7c 100644 --- a/skimage/io/_plugins/pil_plugin.py +++ b/skimage/io/_plugins/pil_plugin.py @@ -45,7 +45,23 @@ def imread(fname, dtype=None): site = "http://pillow.readthedocs.org/en/latest/installation.html#external-libraries" raise ValueError('Could not load "%s"\nPlease see documentation at: %s' % (fname, site)) else: - return pil_to_ndarray(im, dtype) + return _get_pil_frames(im, dtype) + + +def _get_pil_frames(img, dtype): + frames = [] + try: + i = 0 + while True: + frames.append(pil_to_ndarray(img, dtype=dtype, + close_fid=False)) + i += 1 + img.seek(i) + except EOFError: + pass + finally: + img.fp.close() + return np.dstack(frames) def pil_to_ndarray(im, dtype=None, close_fid=True): diff --git a/skimage/io/collection.py b/skimage/io/collection.py index 15ed5cfb..df5af2c2 100644 --- a/skimage/io/collection.py +++ b/skimage/io/collection.py @@ -345,6 +345,8 @@ class ImageCollection(object): if load_func is None: from ._io import imread self.load_func = imread + # treat each one as a multi image, then we access + # them from there else: self.load_func = load_func @@ -412,7 +414,7 @@ class ImageCollection(object): def _check_imgnum(self, n): """Check that the given image number is valid.""" - num = len(self.files) + num = len(self.nimages) if -num <= n < num: n = n % num else: @@ -427,7 +429,7 @@ class ImageCollection(object): def __len__(self): """Number of images in collection.""" - return len(self.files) + return self.nimages def __str__(self): return str(self.files)