mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-03 15:10:30 +08:00
Fixes to MultiImage, added tests for it, plus a test TIF image.
This commit is contained in:
+13
-7
@@ -44,23 +44,25 @@ class MultiImage(object):
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> img = MultiImage(fname) #doctest: +SKIP
|
||||
>>> import os.path
|
||||
>>> fname = os.path.join('tests', 'data', 'multipage.tif')
|
||||
|
||||
>>> img = MultiImage(fname)
|
||||
>>> len(img)
|
||||
3
|
||||
2
|
||||
>>> for frame in img:
|
||||
... print frame.shape
|
||||
(576, 384)
|
||||
(576, 384)
|
||||
(576, 384)
|
||||
(15, 10)
|
||||
(15, 10)
|
||||
"""
|
||||
def __init__(self, filename, conserve_memory=True):
|
||||
"""Load a multi-img"""
|
||||
self._filename = filename
|
||||
self.conserve_memory = conserve_memory
|
||||
self._conserve_memory = conserve_memory
|
||||
self._cached = None
|
||||
|
||||
img = Image.open(self._filename)
|
||||
if self.conserve_memory:
|
||||
if self._conserve_memory:
|
||||
self._numframes = self._find_numframes(img)
|
||||
else:
|
||||
self._frames = self._getallframes(img)
|
||||
@@ -70,6 +72,10 @@ class MultiImage(object):
|
||||
def filename(self):
|
||||
return self._filename
|
||||
|
||||
@property
|
||||
def conserve_memory(self):
|
||||
return self._conserve_memory
|
||||
|
||||
def _find_numframes(self, img):
|
||||
"""Find the number of frames in the multi-img."""
|
||||
i = 0
|
||||
|
||||
Binary file not shown.
@@ -44,6 +44,48 @@ class TestImageCollection():
|
||||
assert self.collection[1].ndim == 2
|
||||
|
||||
|
||||
class TestMultiImage():
|
||||
|
||||
def setUp(self):
|
||||
# This multipage TIF file was created with imagemagick:
|
||||
# convert im1.tif im2.tif -adjoin multipage.tif
|
||||
self.img = io.MultiImage(os.path.join('data', 'multipage.tif'))
|
||||
|
||||
def test_len(self):
|
||||
assert len(self.img) == 2
|
||||
|
||||
def test_getitem(self):
|
||||
num = len(self.img)
|
||||
for i in range(-num, num):
|
||||
assert type(self.img[i]) is np.ndarray
|
||||
assert_array_almost_equal(self.img[0],
|
||||
self.img[-num])
|
||||
|
||||
#assert_raises expects a callable, hence this do-very-little func
|
||||
def return_img(n):
|
||||
return self.img[n]
|
||||
assert_raises(IndexError, return_img, num)
|
||||
assert_raises(IndexError, return_img, -num-1)
|
||||
|
||||
def test_files_property(self):
|
||||
assert isinstance(self.img.filename, basestring)
|
||||
|
||||
def set_filename(f):
|
||||
self.img.filename = f
|
||||
assert_raises(AttributeError, set_filename, 'newfile')
|
||||
|
||||
def test_conserve_memory_property(self):
|
||||
assert isinstance(self.img.conserve_memory, bool)
|
||||
|
||||
def set_mem(val):
|
||||
self.img.conserve_memory = val
|
||||
assert_raises(AttributeError, set_mem, True)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_module_suite()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user