mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-12 07:29:48 +08:00
Fix failing tests
This commit is contained in:
committed by
Stefan van der Walt
parent
d27fadb5cf
commit
b4838c3bd9
@@ -59,28 +59,33 @@ def pil_to_ndarray(im, dtype=None, img_num=None):
|
||||
Refer to ``imread``.
|
||||
|
||||
"""
|
||||
if im.mode == 'P':
|
||||
if _palette_is_grayscale(im):
|
||||
im = im.convert('L')
|
||||
else:
|
||||
im = im.convert('RGB')
|
||||
elif im.mode == '1':
|
||||
im = im.convert('L')
|
||||
elif 'A' in im.mode:
|
||||
im = im.convert('RGBA')
|
||||
|
||||
frames = []
|
||||
i = 0
|
||||
while 1:
|
||||
frame = im.seek(i)
|
||||
try:
|
||||
im.seek(i)
|
||||
except EOFError:
|
||||
break
|
||||
|
||||
# seeking must be done sequentially
|
||||
if img_num and not i == img_num:
|
||||
i += 1
|
||||
continue
|
||||
|
||||
frame = im
|
||||
if im.mode == 'P':
|
||||
if _palette_is_grayscale(im):
|
||||
frame = im.convert('L')
|
||||
else:
|
||||
frame = im.convert('RGB')
|
||||
elif im.mode == '1':
|
||||
frame = im.convert('L')
|
||||
|
||||
elif 'A' in im.mode:
|
||||
frame = im.convert('RGBA')
|
||||
|
||||
if im.mode.startswith('I;16'):
|
||||
shape = frame.size
|
||||
shape = im.size
|
||||
dtype = '>u2' if im.mode.endswith('B') else '<u2'
|
||||
if 'S' in im.mode:
|
||||
dtype = dtype.replace('u', 'i')
|
||||
@@ -93,8 +98,13 @@ def pil_to_ndarray(im, dtype=None, img_num=None):
|
||||
frames.append(frame)
|
||||
i += 1
|
||||
|
||||
im.fp.close()
|
||||
return np.dstack(frames)
|
||||
if hasattr(im, 'fp') and im.fp:
|
||||
im.fp.close()
|
||||
|
||||
if len(frames) > 1:
|
||||
return np.array(frames)
|
||||
else:
|
||||
return frames[0]
|
||||
|
||||
|
||||
def _palette_is_grayscale(pil_image):
|
||||
|
||||
@@ -128,8 +128,9 @@ class MultiImage(object):
|
||||
self._numframes = self._find_numframes(img)
|
||||
|
||||
else:
|
||||
self._frames = self._getallframes(img)
|
||||
self._numframes = len(self._frames)
|
||||
self._frames = self._getallframes()
|
||||
# TODO: this is not correct
|
||||
self._numframes = self._frames.shape[0]
|
||||
|
||||
if not self.tif_img:
|
||||
img.fp.close()
|
||||
@@ -164,16 +165,15 @@ class MultiImage(object):
|
||||
|
||||
else:
|
||||
from ._io import imread
|
||||
return imread(self.filename, self._dtype, framenum)
|
||||
return imread(self.filename, self._dtype, img_num=framenum)
|
||||
|
||||
def _getallframes(self, img):
|
||||
def _getallframes(self):
|
||||
"""Extract all frames from the multi-img."""
|
||||
if self.tif_img:
|
||||
return [p.asarray() for p in self.tif_img.pages]
|
||||
|
||||
return self.tif_img.asarray()
|
||||
else:
|
||||
from ._io import imread
|
||||
return imread(img, self._dtype)
|
||||
return imread(self.filename, self._dtype)
|
||||
|
||||
def __getitem__(self, n):
|
||||
"""Return the n-th frame as an array.
|
||||
@@ -398,7 +398,7 @@ class ImageCollection(object):
|
||||
|
||||
def _check_imgnum(self, n):
|
||||
"""Check that the given image number is valid."""
|
||||
num = len(self.nimages)
|
||||
num = len(self.files)
|
||||
if -num <= n < num:
|
||||
n = n % num
|
||||
else:
|
||||
@@ -413,7 +413,7 @@ class ImageCollection(object):
|
||||
|
||||
def __len__(self):
|
||||
"""Number of images in collection."""
|
||||
return self.nimages
|
||||
return len(self.files)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.files)
|
||||
|
||||
Reference in New Issue
Block a user