mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-01 03:09:01 +08:00
Fix implementation of pil_to_ndarray in MultiImage
This commit is contained in:
committed by
Stefan van der Walt
parent
93c6d010e6
commit
39d9dcf20e
@@ -48,7 +48,7 @@ def imread(fname, dtype=None):
|
||||
return pil_to_ndarray(im, dtype)
|
||||
|
||||
|
||||
def pil_to_ndarray(im, dtype=None):
|
||||
def pil_to_ndarray(im, dtype=None, close_fid=True):
|
||||
"""Import a PIL Image object to an ndarray, in memory.
|
||||
|
||||
Parameters
|
||||
@@ -74,7 +74,7 @@ def pil_to_ndarray(im, dtype=None):
|
||||
elif 'A' in im.mode:
|
||||
im = im.convert('RGBA')
|
||||
im = np.array(im, dtype=dtype)
|
||||
if fp is not None:
|
||||
if fp is not None and close_fid:
|
||||
fp.close()
|
||||
return im
|
||||
|
||||
|
||||
@@ -131,7 +131,8 @@ class MultiImage(object):
|
||||
self._frames = self._getallframes(img)
|
||||
self._numframes = len(self._frames)
|
||||
|
||||
img.close()
|
||||
if not self.tif_img:
|
||||
img.fp.close()
|
||||
|
||||
@property
|
||||
def filename(self):
|
||||
@@ -178,11 +179,15 @@ class MultiImage(object):
|
||||
try:
|
||||
i = 0
|
||||
while True:
|
||||
frames.append(pil_to_ndarray(img, dtype=self._dtype))
|
||||
frames.append(pil_to_ndarray(img, dtype=self._dtype,
|
||||
close_fid=False))
|
||||
i += 1
|
||||
img.seek(i)
|
||||
except EOFError:
|
||||
return frames
|
||||
pass
|
||||
finally:
|
||||
img.fp.close()
|
||||
return frames
|
||||
|
||||
def __getitem__(self, n):
|
||||
"""Return the n-th frame as an array.
|
||||
|
||||
Reference in New Issue
Block a user