mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-29 16:00:12 +08:00
b980e7bb98
Use files from tifffile 0.6.0 package Skip failing doctests Skip failing doctests Fix doctest skipping Skip another doctest Skip another doctest Bump to tifffile 0.6.1 and add test Use latest tifffile Sync with 0.6.2 Skip doctests Skip one more doctest Another doctest skip Use relative import in test Fix import and failing doctest
67 lines
1.8 KiB
Python
67 lines
1.8 KiB
Python
import os
|
|
import numpy as np
|
|
|
|
try:
|
|
import skimage as si
|
|
except Exception:
|
|
si = None
|
|
|
|
from numpy.testing import (
|
|
assert_array_equal, assert_array_almost_equal, run_module_suite)
|
|
from numpy.testing.decorators import skipif
|
|
|
|
from tempfile import NamedTemporaryFile
|
|
from .tifffile import imread, imsave
|
|
|
|
|
|
np.random.seed(0)
|
|
|
|
|
|
@skipif(si is None)
|
|
def test_imread_uint16():
|
|
expected = np.load(os.path.join(si.data_dir, 'chessboard_GRAY_U8.npy'))
|
|
img = imread(os.path.join(si.data_dir, 'chessboard_GRAY_U16.tif'))
|
|
assert img.dtype == np.uint16
|
|
assert_array_almost_equal(img, expected)
|
|
|
|
|
|
@skipif(si is None)
|
|
def test_imread_uint16_big_endian():
|
|
expected = np.load(os.path.join(si.data_dir, 'chessboard_GRAY_U8.npy'))
|
|
img = imread(os.path.join(si.data_dir, 'chessboard_GRAY_U16B.tif'))
|
|
assert img.dtype == np.uint16
|
|
assert_array_almost_equal(img, expected)
|
|
|
|
|
|
def test_extension():
|
|
from .tifffile.tifffile import decodelzw
|
|
import types
|
|
assert isinstance(decodelzw, types.BuiltinFunctionType), type(decodelzw)
|
|
|
|
|
|
class TestSave:
|
|
|
|
def roundtrip(self, dtype, x):
|
|
f = NamedTemporaryFile(suffix='.tif')
|
|
fname = f.name
|
|
f.close()
|
|
imsave(fname, x)
|
|
y = imread(fname)
|
|
assert_array_equal(x, y)
|
|
|
|
def test_imsave_roundtrip(self):
|
|
for shape in [(10, 10), (10, 10, 3), (10, 10, 4)]:
|
|
for dtype in (np.uint8, np.uint16, np.float32, np.int16,
|
|
np.float64):
|
|
x = np.random.rand(*shape)
|
|
|
|
if not np.issubdtype(dtype, float):
|
|
x = (x * np.iinfo(dtype).max).astype(dtype)
|
|
else:
|
|
x = x.astype(dtype)
|
|
yield self.roundtrip, dtype, x
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run_module_suite()
|