mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-07 01:08:52 +08:00
Merge pull request #1502 from blink1073/test-mulitpage-rgb-tiff
Add Test for Multipage RGB TIFF
This commit is contained in:
Binary file not shown.
@@ -114,6 +114,9 @@ def pil_to_ndarray(im, dtype=None, img_num=None):
|
||||
frames.append(frame)
|
||||
i += 1
|
||||
|
||||
if img_num is not None:
|
||||
break
|
||||
|
||||
if hasattr(im, 'fp') and im.fp:
|
||||
im.fp.close()
|
||||
|
||||
|
||||
@@ -254,7 +254,7 @@ class ImageCollection(object):
|
||||
kwargs = self.load_func_kwargs
|
||||
if self._frame_index:
|
||||
fname, img_num = self._frame_index[n]
|
||||
if img_num > 0:
|
||||
if img_num is not None:
|
||||
self.data[idx] = self.load_func(fname, img_num=img_num,
|
||||
**kwargs)
|
||||
else:
|
||||
|
||||
@@ -61,20 +61,6 @@ def test_bilevel():
|
||||
assert_array_equal(img.astype(bool), expected)
|
||||
|
||||
|
||||
@skipif(not imread_available)
|
||||
def test_imread_separate_channels():
|
||||
# Test that imread returns RGBA values contiguously even when they are
|
||||
# stored in separate planes.
|
||||
x = np.random.rand(3, 16, 8)
|
||||
f = NamedTemporaryFile(suffix='.tif')
|
||||
fname = f.name
|
||||
f.close()
|
||||
imsave(fname, x, plugin='tifffile')
|
||||
img = imread(fname, plugin='tifffile')
|
||||
os.remove(fname)
|
||||
assert img.shape == (16, 8, 3), img.shape
|
||||
|
||||
|
||||
class TestSave:
|
||||
def roundtrip(self, x, scaling=1):
|
||||
f = NamedTemporaryFile(suffix='.png')
|
||||
|
||||
@@ -3,6 +3,7 @@ import os
|
||||
import numpy as np
|
||||
from numpy.testing import assert_raises, assert_equal, assert_allclose
|
||||
|
||||
from skimage.io import use_plugin
|
||||
from skimage import data_dir
|
||||
from skimage.io.collection import MultiImage, ImageCollection
|
||||
|
||||
@@ -14,7 +15,8 @@ class TestMultiImage():
|
||||
def setUp(self):
|
||||
# This multipage TIF file was created with imagemagick:
|
||||
# convert im1.tif im2.tif -adjoin multipage.tif
|
||||
paths = [os.path.join(data_dir, 'multipage.tif'),
|
||||
use_plugin('pil')
|
||||
paths = [os.path.join(data_dir, 'multipage_rgb.tif'),
|
||||
os.path.join(data_dir, 'no_time_for_that.gif')]
|
||||
self.imgs = [MultiImage(paths[0]),
|
||||
MultiImage(paths[0], conserve_memory=False),
|
||||
@@ -24,6 +26,12 @@ class TestMultiImage():
|
||||
ImageCollection(paths[1], conserve_memory=False),
|
||||
ImageCollection('%s:%s' % (paths[0], paths[1]))]
|
||||
|
||||
def test_shapes(self):
|
||||
img = self.imgs[-1]
|
||||
imgs = img[:]
|
||||
assert imgs[0].shape == imgs[1].shape
|
||||
assert imgs[0].shape == (10, 10, 3)
|
||||
|
||||
def test_len(self):
|
||||
assert len(self.imgs[0]) == len(self.imgs[1]) == 2
|
||||
assert len(self.imgs[2]) == len(self.imgs[3]) == 24
|
||||
|
||||
@@ -50,6 +50,24 @@ def test_imread_flatten():
|
||||
assert np.sctype2char(img.dtype) in np.typecodes['AllInteger']
|
||||
|
||||
|
||||
def test_imread_separate_channels():
|
||||
# Test that imread returns RGBA values contiguously even when they are
|
||||
# stored in separate planes.
|
||||
x = np.random.rand(3, 16, 8)
|
||||
f = NamedTemporaryFile(suffix='.tif')
|
||||
fname = f.name
|
||||
f.close()
|
||||
imsave(fname, x)
|
||||
img = imread(fname)
|
||||
os.remove(fname)
|
||||
assert img.shape == (16, 8, 3), img.shape
|
||||
|
||||
|
||||
def test_imread_multipage_rgb_tif():
|
||||
img = imread(os.path.join(data_dir, 'multipage_rgb.tif'))
|
||||
assert img.shape == (2, 10, 10, 3), img.shape
|
||||
|
||||
|
||||
def test_imread_palette():
|
||||
img = imread(os.path.join(data_dir, 'palette_gray.png'))
|
||||
assert img.ndim == 2
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
import skimage as si
|
||||
import skimage.io as sio
|
||||
from ... import data_dir
|
||||
from .. import imread, imsave, use_plugin, reset_plugins
|
||||
import numpy as np
|
||||
|
||||
from numpy.testing import (
|
||||
@@ -8,38 +8,42 @@ from numpy.testing import (
|
||||
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
_plugins = sio.plugin_order()
|
||||
sio.use_plugin('tifffile')
|
||||
|
||||
|
||||
np.random.seed(0)
|
||||
def setup():
|
||||
use_plugin('tifffile')
|
||||
np.random.seed(0)
|
||||
|
||||
|
||||
def teardown():
|
||||
sio.reset_plugins()
|
||||
reset_plugins()
|
||||
|
||||
|
||||
def test_imread_uint16():
|
||||
expected = np.load(os.path.join(si.data_dir, 'chessboard_GRAY_U8.npy'))
|
||||
img = sio.imread(os.path.join(si.data_dir, 'chessboard_GRAY_U16.tif'))
|
||||
expected = np.load(os.path.join(data_dir, 'chessboard_GRAY_U8.npy'))
|
||||
img = imread(os.path.join(data_dir, 'chessboard_GRAY_U16.tif'))
|
||||
assert img.dtype == np.uint16
|
||||
assert_array_almost_equal(img, expected)
|
||||
|
||||
|
||||
def test_imread_uint16_big_endian():
|
||||
expected = np.load(os.path.join(si.data_dir, 'chessboard_GRAY_U8.npy'))
|
||||
img = sio.imread(os.path.join(si.data_dir, 'chessboard_GRAY_U16B.tif'))
|
||||
expected = np.load(os.path.join(data_dir, 'chessboard_GRAY_U8.npy'))
|
||||
img = imread(os.path.join(data_dir, 'chessboard_GRAY_U16B.tif'))
|
||||
assert img.dtype == np.uint16
|
||||
assert_array_almost_equal(img, expected)
|
||||
|
||||
|
||||
def test_imread_multipage_rgb_tif():
|
||||
img = imread(os.path.join(data_dir, 'multipage_rgb.tif'))
|
||||
assert img.shape == (2, 10, 10, 3), img.shape
|
||||
|
||||
|
||||
class TestSave:
|
||||
def roundtrip(self, dtype, x):
|
||||
f = NamedTemporaryFile(suffix='.tif')
|
||||
fname = f.name
|
||||
f.close()
|
||||
sio.imsave(fname, x)
|
||||
y = sio.imread(fname)
|
||||
imsave(fname, x)
|
||||
y = imread(fname)
|
||||
assert_array_equal(x, y)
|
||||
|
||||
def test_imsave_roundtrip(self):
|
||||
|
||||
Reference in New Issue
Block a user