mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-02 13:03:48 +08:00
Allow multiple frames in PIL data in imread
This commit is contained in:
committed by
Stefan van der Walt
parent
39d9dcf20e
commit
4298b8babc
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user