Fix implementation of pil_to_ndarray in MultiImage

This commit is contained in:
Steven Silvester
2014-10-21 10:20:15 -05:00
committed by Stefan van der Walt
parent 93c6d010e6
commit 39d9dcf20e
2 changed files with 10 additions and 5 deletions
+2 -2
View File
@@ -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
+8 -3
View File
@@ -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.