mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-05 13:44:59 +08:00
Handle more warnings and reset io plugins as needed
Reset plugins prior to running collections test Handle warnings in morphology pkg Add __init__ for morpohology tests Handle warnings for novice pkg Handle warnings for restoration pkg Handle warnings for segmentation pkg Handle warnings for _shared pkg Handle warnings for transform pkg Handle warnings for util pkg Handle warnings in viewer module
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
import warnings
|
||||
warnings.simplefilter('error')
|
||||
@@ -5,6 +5,7 @@ from numpy.testing import assert_raises, assert_equal, assert_allclose
|
||||
|
||||
from skimage import data_dir
|
||||
from skimage.io.collection import ImageCollection, alphanumeric_key
|
||||
from skimage.io import reset_plugins
|
||||
|
||||
|
||||
def test_string_split():
|
||||
@@ -31,6 +32,7 @@ class TestImageCollection():
|
||||
for pic in ['camera.png', 'moon.png']]
|
||||
|
||||
def setUp(self):
|
||||
reset_plugins()
|
||||
# Generic image collection with images of different shapes.
|
||||
self.images = ImageCollection(self.pattern)
|
||||
# Image collection with images having shapes that match.
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
import warnings
|
||||
warnings.simplefilter('error')
|
||||
@@ -4,6 +4,7 @@ from numpy import testing
|
||||
from skimage import data, color
|
||||
from skimage.util import img_as_bool
|
||||
from skimage.morphology import binary, grey, selem
|
||||
from skimage._shared.utils import all_warnings
|
||||
from scipy import ndimage
|
||||
|
||||
|
||||
@@ -14,35 +15,40 @@ bw_img = img > 100
|
||||
def test_non_square_image():
|
||||
strel = selem.square(3)
|
||||
binary_res = binary.binary_erosion(bw_img[:100, :200], strel)
|
||||
grey_res = img_as_bool(grey.erosion(bw_img[:100, :200], strel))
|
||||
with all_warnings(): # precision loss
|
||||
grey_res = img_as_bool(grey.erosion(bw_img[:100, :200], strel))
|
||||
testing.assert_array_equal(binary_res, grey_res)
|
||||
|
||||
|
||||
def test_binary_erosion():
|
||||
strel = selem.square(3)
|
||||
binary_res = binary.binary_erosion(bw_img, strel)
|
||||
grey_res = img_as_bool(grey.erosion(bw_img, strel))
|
||||
with all_warnings(): # precision loss
|
||||
grey_res = img_as_bool(grey.erosion(bw_img, strel))
|
||||
testing.assert_array_equal(binary_res, grey_res)
|
||||
|
||||
|
||||
def test_binary_dilation():
|
||||
strel = selem.square(3)
|
||||
binary_res = binary.binary_dilation(bw_img, strel)
|
||||
grey_res = img_as_bool(grey.dilation(bw_img, strel))
|
||||
with all_warnings(): # precision loss
|
||||
grey_res = img_as_bool(grey.dilation(bw_img, strel))
|
||||
testing.assert_array_equal(binary_res, grey_res)
|
||||
|
||||
|
||||
def test_binary_closing():
|
||||
strel = selem.square(3)
|
||||
binary_res = binary.binary_closing(bw_img, strel)
|
||||
grey_res = img_as_bool(grey.closing(bw_img, strel))
|
||||
with all_warnings(): # precision loss
|
||||
grey_res = img_as_bool(grey.closing(bw_img, strel))
|
||||
testing.assert_array_equal(binary_res, grey_res)
|
||||
|
||||
|
||||
def test_binary_opening():
|
||||
strel = selem.square(3)
|
||||
binary_res = binary.binary_opening(bw_img, strel)
|
||||
grey_res = img_as_bool(grey.opening(bw_img, strel))
|
||||
with all_warnings(): # precision loss
|
||||
grey_res = img_as_bool(grey.opening(bw_img, strel))
|
||||
testing.assert_array_equal(binary_res, grey_res)
|
||||
|
||||
|
||||
@@ -51,7 +57,8 @@ def test_selem_overflow():
|
||||
img = np.zeros((20, 20))
|
||||
img[2:19, 2:19] = 1
|
||||
binary_res = binary.binary_erosion(img, strel)
|
||||
grey_res = img_as_bool(grey.erosion(img, strel))
|
||||
with all_warnings(): # precision loss
|
||||
grey_res = img_as_bool(grey.erosion(img, strel))
|
||||
testing.assert_array_equal(binary_res, grey_res)
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import numpy as np
|
||||
from numpy.testing import assert_array_equal, run_module_suite
|
||||
|
||||
from skimage.morphology import label
|
||||
from skimage.morphology import label as _label
|
||||
import skimage.measure._ccomp as ccomp
|
||||
from warnings import catch_warnings
|
||||
from skimage._shared.utils import skimage_deprecation
|
||||
|
||||
from skimage._shared.utils import all_warnings
|
||||
np.random.seed(0)
|
||||
|
||||
# The background label value
|
||||
@@ -13,6 +11,12 @@ np.random.seed(0)
|
||||
BG = -1
|
||||
|
||||
|
||||
def label(*args, **kwargs):
|
||||
"""Wrap the label function to avoid deprecation warning"""
|
||||
with all_warnings():
|
||||
return _label(*args, **kwargs)
|
||||
|
||||
|
||||
class TestConnectedComponents:
|
||||
def setup(self):
|
||||
self.x = np.array([[0, 0, 3, 2, 1, 9],
|
||||
@@ -34,7 +38,7 @@ class TestConnectedComponents:
|
||||
def test_random(self):
|
||||
x = (np.random.rand(20, 30) * 5).astype(np.int)
|
||||
|
||||
with catch_warnings():
|
||||
with all_warnings():
|
||||
labels = label(x)
|
||||
|
||||
n = labels.max()
|
||||
@@ -46,13 +50,13 @@ class TestConnectedComponents:
|
||||
x = np.array([[0, 0, 1],
|
||||
[0, 1, 0],
|
||||
[1, 0, 0]])
|
||||
with catch_warnings():
|
||||
with all_warnings():
|
||||
assert_array_equal(label(x), x)
|
||||
|
||||
def test_4_vs_8(self):
|
||||
x = np.array([[0, 1],
|
||||
[1, 0]], dtype=int)
|
||||
with catch_warnings():
|
||||
with all_warnings():
|
||||
assert_array_equal(label(x, 4),
|
||||
[[0, 1],
|
||||
[2, 3]])
|
||||
@@ -65,7 +69,7 @@ class TestConnectedComponents:
|
||||
[1, 1, 5],
|
||||
[0, 0, 0]])
|
||||
|
||||
with catch_warnings():
|
||||
with all_warnings():
|
||||
assert_array_equal(label(x), [[0, 1, 1],
|
||||
[0, 0, 2],
|
||||
[3, 3, 3]])
|
||||
@@ -101,7 +105,7 @@ class TestConnectedComponents:
|
||||
[0, 0, 6],
|
||||
[5, 5, 5]])
|
||||
|
||||
with catch_warnings():
|
||||
with all_warnings():
|
||||
assert_array_equal(label(x, return_num=True)[1], 4)
|
||||
|
||||
assert_array_equal(label(x, background=0, return_num=True)[1], 3)
|
||||
@@ -152,7 +156,7 @@ class TestConnectedComponents3d:
|
||||
def test_random(self):
|
||||
x = (np.random.rand(20, 30) * 5).astype(np.int)
|
||||
|
||||
with catch_warnings():
|
||||
with all_warnings():
|
||||
labels = label(x)
|
||||
|
||||
n = labels.max()
|
||||
@@ -165,7 +169,7 @@ class TestConnectedComponents3d:
|
||||
x[0, 2, 2] = 1
|
||||
x[1, 1, 1] = 1
|
||||
x[2, 0, 0] = 1
|
||||
with catch_warnings():
|
||||
with all_warnings():
|
||||
assert_array_equal(label(x), x)
|
||||
|
||||
def test_4_vs_8(self):
|
||||
@@ -174,7 +178,7 @@ class TestConnectedComponents3d:
|
||||
x[1, 0, 0] = 1
|
||||
label4 = x.copy()
|
||||
label4[1, 0, 0] = 2
|
||||
with catch_warnings():
|
||||
with all_warnings():
|
||||
assert_array_equal(label(x, 4), label4)
|
||||
assert_array_equal(label(x, 8), x)
|
||||
|
||||
@@ -202,7 +206,7 @@ class TestConnectedComponents3d:
|
||||
[BG, 0, 1],
|
||||
[BG, BG, BG]])
|
||||
|
||||
with catch_warnings():
|
||||
with all_warnings():
|
||||
assert_array_equal(label(x), lnb)
|
||||
|
||||
assert_array_equal(label(x, background=0), lb)
|
||||
@@ -240,7 +244,7 @@ class TestConnectedComponents3d:
|
||||
[0, 0, 6],
|
||||
[5, 5, 5]])
|
||||
|
||||
with catch_warnings():
|
||||
with all_warnings():
|
||||
assert_array_equal(label(x, return_num=True)[1], 4)
|
||||
|
||||
assert_array_equal(label(x, background=0, return_num=True)[1], 3)
|
||||
|
||||
@@ -7,6 +7,7 @@ from scipy import ndimage
|
||||
import skimage
|
||||
from skimage import data_dir
|
||||
from skimage.morphology import grey, selem
|
||||
from skimage._shared.utils import all_warnings
|
||||
|
||||
|
||||
lena = np.load(os.path.join(data_dir, 'lena_GRAY_U8.npy'))
|
||||
@@ -170,9 +171,12 @@ def test_3d_fallback_white_tophat():
|
||||
image[2, 2:4, 2:4] = 1
|
||||
image[3, 2:5, 2:5] = 1
|
||||
image[4, 3:5, 3:5] = 1
|
||||
new_image = grey.white_tophat(image)
|
||||
|
||||
with all_warnings(): # scipy upstream warning
|
||||
new_image = grey.white_tophat(image)
|
||||
footprint = ndimage.generate_binary_structure(3,1)
|
||||
image_expected = ndimage.white_tophat(image,footprint=footprint)
|
||||
with all_warnings(): # scipy upstream warning
|
||||
image_expected = ndimage.white_tophat(image,footprint=footprint)
|
||||
testing.assert_array_equal(new_image, image_expected)
|
||||
|
||||
def test_3d_fallback_black_tophat():
|
||||
@@ -180,9 +184,12 @@ def test_3d_fallback_black_tophat():
|
||||
image[2, 2:4, 2:4] = 0
|
||||
image[3, 2:5, 2:5] = 0
|
||||
image[4, 3:5, 3:5] = 0
|
||||
new_image = grey.black_tophat(image)
|
||||
|
||||
with all_warnings(): # scipy upstream warning
|
||||
new_image = grey.black_tophat(image)
|
||||
footprint = ndimage.generate_binary_structure(3,1)
|
||||
image_expected = ndimage.black_tophat(image,footprint=footprint)
|
||||
with all_warnings(): # scipy upstream warning
|
||||
image_expected = ndimage.black_tophat(image,footprint=footprint)
|
||||
testing.assert_array_equal(new_image, image_expected)
|
||||
|
||||
def test_2d_ndimage_equivalence():
|
||||
@@ -216,10 +223,12 @@ class TestDTypes():
|
||||
self.expected_closing = np.load(fname_closing)[arrname]
|
||||
|
||||
def _test_image(self, image):
|
||||
result_opening = grey.opening(image, self.disk)
|
||||
with all_warnings(): # precision loss
|
||||
result_opening = grey.opening(image, self.disk)
|
||||
testing.assert_equal(result_opening, self.expected_opening)
|
||||
|
||||
result_closing = grey.closing(image, self.disk)
|
||||
with all_warnings(): # precision loss
|
||||
result_closing = grey.closing(image, self.disk)
|
||||
testing.assert_equal(result_closing, self.expected_closing)
|
||||
|
||||
def test_float(self):
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
import warnings
|
||||
warnings.simplefilter('error')
|
||||
@@ -7,16 +7,12 @@ from skimage import novice
|
||||
from skimage.novice._novice import (array_to_xy_origin, xy_to_array_origin,
|
||||
rgb_transpose)
|
||||
from skimage import data_dir
|
||||
|
||||
from skimage._shared.utils import all_warnings
|
||||
|
||||
IMAGE_PATH = os.path.join(data_dir, "chelsea.png")
|
||||
SMALL_IMAGE_PATH = os.path.join(data_dir, "block.png")
|
||||
|
||||
|
||||
def _array_2d_to_RGBA(array):
|
||||
return np.tile(array[:, :, np.newaxis], (1, 1, 4))
|
||||
|
||||
|
||||
def _array_2d_to_RGBA(array):
|
||||
return np.tile(array[:, :, np.newaxis], (1, 1, 4))
|
||||
|
||||
@@ -62,7 +58,8 @@ def test_modify():
|
||||
assert p.blue <= 128
|
||||
|
||||
s = pic.size
|
||||
pic.size = (pic.width / 2, pic.height / 2)
|
||||
with all_warnings(): # precision loss
|
||||
pic.size = (pic.width / 2, pic.height / 2)
|
||||
assert_equal(pic.size, (int(s[0] / 2), int(s[1] / 2)))
|
||||
|
||||
assert pic.modified
|
||||
@@ -139,7 +136,8 @@ def test_modified_on_set_pixel():
|
||||
|
||||
def test_update_on_save():
|
||||
pic = novice.Picture(array=np.zeros((3, 3, 3)))
|
||||
pic.size = (6, 6)
|
||||
with all_warnings(): # precision loss
|
||||
pic.size = (6, 6)
|
||||
assert pic.modified
|
||||
assert pic.path is None
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
import warnings
|
||||
warnings.simplefilter('error')
|
||||
@@ -7,6 +7,7 @@ from numpy.testing import (run_module_suite, assert_array_almost_equal_nulp,
|
||||
import warnings
|
||||
|
||||
from skimage.restoration import unwrap_phase
|
||||
from skimage._shared.utils import all_warnings
|
||||
|
||||
|
||||
def assert_phase_almost_equal(a, b, *args, **kwargs):
|
||||
@@ -132,9 +133,12 @@ def test_mask():
|
||||
assert_array_almost_equal_nulp(image_unwrapped[:, -1], image[i, -1])
|
||||
|
||||
# Same tests, but forcing use of the 3D unwrapper by reshaping
|
||||
image_wrapped_3d = image_wrapped.reshape((1,) + image_wrapped.shape)
|
||||
image_unwrapped_3d = unwrap_phase(image_wrapped_3d)
|
||||
image_unwrapped_3d -= image_unwrapped_3d[0, 0, 0] # remove phase shift
|
||||
with all_warnings(): # 1 dimension
|
||||
shape = (1,) + image_wrapped.shape
|
||||
image_wrapped_3d = image_wrapped.reshape(shape)
|
||||
image_unwrapped_3d = unwrap_phase(image_wrapped_3d)
|
||||
# remove phase shift
|
||||
image_unwrapped_3d -= image_unwrapped_3d[0, 0, 0]
|
||||
assert_array_almost_equal_nulp(image_unwrapped_3d[:, :, -1], image[i, -1])
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
import warnings
|
||||
warnings.simplefilter('error')
|
||||
@@ -1,6 +1,7 @@
|
||||
import numpy as np
|
||||
from skimage.segmentation import random_walker
|
||||
from skimage.transform import resize
|
||||
from skimage._shared.utils import all_warnings
|
||||
|
||||
|
||||
def make_2d_syntheticdata(lx, ly=None):
|
||||
@@ -74,10 +75,12 @@ def test_2d_cg():
|
||||
lx = 70
|
||||
ly = 100
|
||||
data, labels = make_2d_syntheticdata(lx, ly)
|
||||
labels_cg = random_walker(data, labels, beta=90, mode='cg')
|
||||
with all_warnings(): # cg mode
|
||||
labels_cg = random_walker(data, labels, beta=90, mode='cg')
|
||||
assert (labels_cg[25:45, 40:60] == 2).all()
|
||||
assert data.shape == labels.shape
|
||||
full_prob = random_walker(data, labels, beta=90, mode='cg',
|
||||
with all_warnings(): # cg mode
|
||||
full_prob = random_walker(data, labels, beta=90, mode='cg',
|
||||
return_full_prob=True)
|
||||
assert (full_prob[1, 25:45, 40:60] >=
|
||||
full_prob[0, 25:45, 40:60]).all()
|
||||
@@ -89,10 +92,12 @@ def test_2d_cg_mg():
|
||||
lx = 70
|
||||
ly = 100
|
||||
data, labels = make_2d_syntheticdata(lx, ly)
|
||||
labels_cg_mg = random_walker(data, labels, beta=90, mode='cg_mg')
|
||||
with all_warnings(): # pyamg optional
|
||||
labels_cg_mg = random_walker(data, labels, beta=90, mode='cg_mg')
|
||||
assert (labels_cg_mg[25:45, 40:60] == 2).all()
|
||||
assert data.shape == labels.shape
|
||||
full_prob = random_walker(data, labels, beta=90, mode='cg_mg',
|
||||
with all_warnings(): # pyamg optional
|
||||
full_prob = random_walker(data, labels, beta=90, mode='cg_mg',
|
||||
return_full_prob=True)
|
||||
assert (full_prob[1, 25:45, 40:60] >=
|
||||
full_prob[0, 25:45, 40:60]).all()
|
||||
@@ -106,7 +111,8 @@ def test_types():
|
||||
data, labels = make_2d_syntheticdata(lx, ly)
|
||||
data = 255 * (data - data.min()) // (data.max() - data.min())
|
||||
data = data.astype(np.uint8)
|
||||
labels_cg_mg = random_walker(data, labels, beta=90, mode='cg_mg')
|
||||
with all_warnings(): # pyamg optional
|
||||
labels_cg_mg = random_walker(data, labels, beta=90, mode='cg_mg')
|
||||
assert (labels_cg_mg[25:45, 40:60] == 2).all()
|
||||
assert data.shape == labels.shape
|
||||
return data, labels_cg_mg
|
||||
@@ -139,7 +145,8 @@ def test_3d():
|
||||
n = 30
|
||||
lx, ly, lz = n, n, n
|
||||
data, labels = make_3d_syntheticdata(lx, ly, lz)
|
||||
labels = random_walker(data, labels, mode='cg')
|
||||
with all_warnings(): # cg mode
|
||||
labels = random_walker(data, labels, mode='cg')
|
||||
assert (labels.reshape(data.shape)[13:17, 13:17, 13:17] == 2).all()
|
||||
assert data.shape == labels.shape
|
||||
return data, labels
|
||||
@@ -152,7 +159,8 @@ def test_3d_inactive():
|
||||
old_labels = np.copy(labels)
|
||||
labels[5:25, 26:29, 26:29] = -1
|
||||
after_labels = np.copy(labels)
|
||||
labels = random_walker(data, labels, mode='cg')
|
||||
with all_warnings(): # cg mode
|
||||
labels = random_walker(data, labels, mode='cg')
|
||||
assert (labels.reshape(data.shape)[13:17, 13:17, 13:17] == 2).all()
|
||||
assert data.shape == labels.shape
|
||||
return data, labels, old_labels, after_labels
|
||||
@@ -162,9 +170,12 @@ def test_multispectral_2d():
|
||||
lx, ly = 70, 100
|
||||
data, labels = make_2d_syntheticdata(lx, ly)
|
||||
data = data[..., np.newaxis].repeat(2, axis=-1) # Expect identical output
|
||||
multi_labels = random_walker(data, labels, mode='cg', multichannel=True)
|
||||
with all_warnings(): # cg mode
|
||||
multi_labels = random_walker(data, labels, mode='cg',
|
||||
multichannel=True)
|
||||
assert data[..., 0].shape == labels.shape
|
||||
single_labels = random_walker(data[..., 0], labels, mode='cg')
|
||||
with all_warnings(): # cg mode
|
||||
single_labels = random_walker(data[..., 0], labels, mode='cg')
|
||||
assert (multi_labels.reshape(labels.shape)[25:45, 40:60] == 2).all()
|
||||
assert data[..., 0].shape == labels.shape
|
||||
return data, multi_labels, single_labels, labels
|
||||
@@ -175,9 +186,12 @@ def test_multispectral_3d():
|
||||
lx, ly, lz = n, n, n
|
||||
data, labels = make_3d_syntheticdata(lx, ly, lz)
|
||||
data = data[..., np.newaxis].repeat(2, axis=-1) # Expect identical output
|
||||
multi_labels = random_walker(data, labels, mode='cg', multichannel=True)
|
||||
with all_warnings(): # cg mode
|
||||
multi_labels = random_walker(data, labels, mode='cg',
|
||||
multichannel=True)
|
||||
assert data[..., 0].shape == labels.shape
|
||||
single_labels = random_walker(data[..., 0], labels, mode='cg')
|
||||
with all_warnings(): # cg mode
|
||||
single_labels = random_walker(data[..., 0], labels, mode='cg')
|
||||
assert (multi_labels.reshape(labels.shape)[13:17, 13:17, 13:17] == 2).all()
|
||||
assert (single_labels.reshape(labels.shape)[13:17, 13:17, 13:17] == 2).all()
|
||||
assert data[..., 0].shape == labels.shape
|
||||
@@ -203,7 +217,8 @@ def test_spacing_0():
|
||||
lz // 4 - small_l // 8] = 2
|
||||
|
||||
# Test with `spacing` kwarg
|
||||
labels_aniso = random_walker(data_aniso, labels_aniso, mode='cg',
|
||||
with all_warnings(): # cg mode
|
||||
labels_aniso = random_walker(data_aniso, labels_aniso, mode='cg',
|
||||
spacing=(1., 1., 0.5))
|
||||
|
||||
assert (labels_aniso[13:17, 13:17, 7:9] == 2).all()
|
||||
@@ -230,8 +245,9 @@ def test_spacing_1():
|
||||
|
||||
# Test with `spacing` kwarg
|
||||
# First, anisotropic along Y
|
||||
labels_aniso = random_walker(data_aniso, labels_aniso, mode='cg',
|
||||
spacing=(1., 2., 1.))
|
||||
with all_warnings(): # using cd mode
|
||||
labels_aniso = random_walker(data_aniso, labels_aniso, mode='cg',
|
||||
spacing=(1., 2., 1.))
|
||||
assert (labels_aniso[13:17, 26:34, 13:17] == 2).all()
|
||||
|
||||
# Rescale `data` along X axis
|
||||
@@ -249,9 +265,10 @@ def test_spacing_1():
|
||||
lz // 2 - small_l // 4] = 2
|
||||
|
||||
# Anisotropic along X
|
||||
labels_aniso2 = random_walker(data_aniso,
|
||||
labels_aniso2,
|
||||
mode='cg', spacing=(2., 1., 1.))
|
||||
with all_warnings(): # cg mode
|
||||
labels_aniso2 = random_walker(data_aniso,
|
||||
labels_aniso2,
|
||||
mode='cg', spacing=(2., 1., 1.))
|
||||
assert (labels_aniso2[26:34, 13:17, 13:17] == 2).all()
|
||||
|
||||
|
||||
@@ -259,14 +276,17 @@ def test_trivial_cases():
|
||||
# When all voxels are labeled
|
||||
img = np.ones((10, 10))
|
||||
labels = np.ones((10, 10))
|
||||
pass_through = random_walker(img, labels)
|
||||
|
||||
with all_warnings(): # using provided labels
|
||||
pass_through = random_walker(img, labels)
|
||||
np.testing.assert_array_equal(pass_through, labels)
|
||||
|
||||
# When all voxels are labeled AND return_full_prob is True
|
||||
labels[:, :5] = 3
|
||||
expected = np.concatenate(((labels == 1)[..., np.newaxis],
|
||||
(labels == 3)[..., np.newaxis]), axis=2)
|
||||
test = random_walker(img, labels, return_full_prob=True)
|
||||
with all_warnings(): # using provided labels
|
||||
test = random_walker(img, labels, return_full_prob=True)
|
||||
np.testing.assert_array_equal(test, expected)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
import warnings
|
||||
warnings.simplefilter('error')
|
||||
@@ -7,6 +7,7 @@ from skimage.transform import (estimate_transform, matrix_transform,
|
||||
SimilarityTransform, AffineTransform,
|
||||
ProjectiveTransform, PolynomialTransform,
|
||||
PiecewiseAffineTransform)
|
||||
from skimage._shared.utils import all_warnings
|
||||
|
||||
|
||||
SRC = np.array([
|
||||
@@ -49,7 +50,7 @@ def test_estimate_transform():
|
||||
|
||||
def test_matrix_transform():
|
||||
tform = AffineTransform(scale=(0.1, 0.5), rotation=2)
|
||||
assert_equal(tform(SRC), matrix_transform(SRC, tform._matrix))
|
||||
assert_equal(tform(SRC), matrix_transform(SRC, tform.params))
|
||||
|
||||
|
||||
def test_similarity_estimation():
|
||||
@@ -209,13 +210,13 @@ def test_union():
|
||||
tform2 = SimilarityTransform(scale=0.1, rotation=0.9)
|
||||
tform3 = SimilarityTransform(scale=0.1 ** 2, rotation=0.3 + 0.9)
|
||||
tform = tform1 + tform2
|
||||
assert_array_almost_equal(tform._matrix, tform3._matrix)
|
||||
assert_array_almost_equal(tform.params, tform3.params)
|
||||
|
||||
tform1 = AffineTransform(scale=(0.1, 0.1), rotation=0.3)
|
||||
tform2 = SimilarityTransform(scale=0.1, rotation=0.9)
|
||||
tform3 = SimilarityTransform(scale=0.1 ** 2, rotation=0.3 + 0.9)
|
||||
tform = tform1 + tform2
|
||||
assert_array_almost_equal(tform._matrix, tform3._matrix)
|
||||
assert_array_almost_equal(tform.params, tform3.params)
|
||||
assert tform.__class__ == ProjectiveTransform
|
||||
|
||||
tform = AffineTransform(scale=(0.1, 0.1), rotation=0.3)
|
||||
@@ -251,10 +252,12 @@ def test_invalid_input():
|
||||
def test_deprecated_params_attributes():
|
||||
for t in ('projective', 'affine', 'similarity'):
|
||||
tform = estimate_transform(t, SRC, DST)
|
||||
assert_equal(tform._matrix, tform.params)
|
||||
with all_warnings(): # _matrix is deprecated
|
||||
assert_equal(tform._matrix, tform.params)
|
||||
|
||||
tform = estimate_transform('polynomial', SRC, DST, order=3)
|
||||
assert_equal(tform._params, tform.params)
|
||||
with all_warnings(): # _params is deprecated
|
||||
assert_equal(tform._params, tform.params)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -3,6 +3,7 @@ from numpy.testing import assert_almost_equal, assert_equal
|
||||
|
||||
import skimage.transform as tf
|
||||
from skimage.draw import line, circle_perimeter, ellipse_perimeter
|
||||
from skimage._shared.utils import all_warnings
|
||||
|
||||
|
||||
def append_desc(func, description):
|
||||
@@ -67,7 +68,8 @@ def test_hough_line_peaks():
|
||||
|
||||
out, angles, d = tf.hough_line(img)
|
||||
|
||||
out, theta, dist = tf.hough_line_peaks(out, angles, d)
|
||||
with all_warnings(): # _ccomp deprecation
|
||||
out, theta, dist = tf.hough_line_peaks(out, angles, d)
|
||||
|
||||
assert_equal(len(dist), 1)
|
||||
assert_almost_equal(dist[0], 80.723, 1)
|
||||
@@ -79,13 +81,19 @@ def test_hough_line_peaks_dist():
|
||||
img[:, 30] = True
|
||||
img[:, 40] = True
|
||||
hspace, angles, dists = tf.hough_line(img)
|
||||
assert len(tf.hough_line_peaks(hspace, angles, dists,
|
||||
min_distance=5)[0]) == 2
|
||||
assert len(tf.hough_line_peaks(hspace, angles, dists,
|
||||
min_distance=15)[0]) == 1
|
||||
with all_warnings(): # _ccomp deprecation
|
||||
assert len(tf.hough_line_peaks(hspace, angles, dists,
|
||||
min_distance=5)[0]) == 2
|
||||
assert len(tf.hough_line_peaks(hspace, angles, dists,
|
||||
min_distance=15)[0]) == 1
|
||||
|
||||
|
||||
def test_hough_line_peaks_angle():
|
||||
with all_warnings(): # _ccomp deprecation
|
||||
check_hough_line_peaks_angle()
|
||||
|
||||
|
||||
def check_hough_line_peaks_angle():
|
||||
img = np.zeros((100, 100), dtype=np.bool_)
|
||||
img[:, 0] = True
|
||||
img[0, :] = True
|
||||
@@ -116,8 +124,9 @@ def test_hough_line_peaks_num():
|
||||
img[:, 30] = True
|
||||
img[:, 40] = True
|
||||
hspace, angles, dists = tf.hough_line(img)
|
||||
assert len(tf.hough_line_peaks(hspace, angles, dists, min_distance=0,
|
||||
min_angle=0, num_peaks=1)[0]) == 1
|
||||
with all_warnings(): # _ccomp deprecation
|
||||
assert len(tf.hough_line_peaks(hspace, angles, dists, min_distance=0,
|
||||
min_angle=0, num_peaks=1)[0]) == 1
|
||||
|
||||
|
||||
def test_hough_circle():
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
import warnings
|
||||
warnings.simplefilter('error')
|
||||
@@ -3,6 +3,7 @@ from numpy.testing import assert_equal, assert_raises
|
||||
from skimage import img_as_int, img_as_float, \
|
||||
img_as_uint, img_as_ubyte
|
||||
from skimage.util.dtype import convert
|
||||
from skimage._shared.utils import all_warnings
|
||||
|
||||
|
||||
dtype_range = {np.uint8: (0, 255),
|
||||
@@ -28,7 +29,9 @@ def test_range():
|
||||
(img_as_float, np.float64),
|
||||
(img_as_uint, np.uint16),
|
||||
(img_as_ubyte, np.ubyte)]:
|
||||
y = f(x)
|
||||
|
||||
with all_warnings(): # precision loss
|
||||
y = f(x)
|
||||
|
||||
omin, omax = dtype_range[dt]
|
||||
|
||||
@@ -59,7 +62,8 @@ def test_range_extra_dtypes():
|
||||
for dtype_in, dt in dtype_pairs:
|
||||
imin, imax = dtype_range_extra[dtype_in]
|
||||
x = np.linspace(imin, imax, 10).astype(dtype_in)
|
||||
y = convert(x, dt)
|
||||
with all_warnings(): # sign loss
|
||||
y = convert(x, dt)
|
||||
omin, omax = dtype_range_extra[dt]
|
||||
yield (_verify_range,
|
||||
"From %s to %s" % (np.dtype(dtype_in), np.dtype(dt)),
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
import warnings
|
||||
warnings.simplefilter('error')
|
||||
@@ -12,6 +12,7 @@ from skimage.viewer.plugins import (
|
||||
PlotPlugin)
|
||||
from skimage.viewer.plugins.base import Plugin
|
||||
from skimage.viewer.widgets import Slider
|
||||
from skimage._shared.utils import all_warnings
|
||||
|
||||
|
||||
def setup_line_profile(image, limits='image'):
|
||||
@@ -66,8 +67,9 @@ def test_line_profile_dynamic():
|
||||
assert_almost_equal(np.std(line), 0.229, 3)
|
||||
assert_almost_equal(np.max(line) - np.min(line), 0.725, 1)
|
||||
|
||||
viewer.image = skimage.img_as_float(median(image,
|
||||
selem=disk(radius=3)))
|
||||
with all_warnings(): # precision loss
|
||||
viewer.image = skimage.img_as_float(median(image,
|
||||
selem=disk(radius=3)))
|
||||
|
||||
line = lp.get_profiles()[-1][0]
|
||||
assert_almost_equal(np.std(viewer.image), 0.198, 3)
|
||||
@@ -159,7 +161,8 @@ def test_plugin():
|
||||
viewer = ImageViewer(img)
|
||||
|
||||
def median_filter(img, radius=3):
|
||||
return median(img, selem=disk(radius=radius))
|
||||
with all_warnings(): # precision loss
|
||||
return median(img, selem=disk(radius=radius))
|
||||
|
||||
plugin = Plugin(image_filter=median_filter)
|
||||
viewer += plugin
|
||||
|
||||
@@ -8,6 +8,7 @@ from skimage.filters import sobel
|
||||
from numpy.testing import assert_equal
|
||||
from numpy.testing.decorators import skipif
|
||||
from skimage._shared.version_requirements import is_installed
|
||||
from skimage._shared.utils import all_warnings
|
||||
|
||||
|
||||
@skipif(not viewer_available)
|
||||
@@ -66,7 +67,9 @@ def test_viewer_with_overlay():
|
||||
|
||||
ov.color = 3
|
||||
assert_equal(ov.color, 'yellow')
|
||||
viewer.save_to_file(filename)
|
||||
|
||||
with all_warnings(): # precision loss
|
||||
viewer.save_to_file(filename)
|
||||
ov.display_filtered_image(img)
|
||||
assert_equal(ov.overlay, img)
|
||||
ov.overlay = None
|
||||
|
||||
@@ -8,6 +8,7 @@ from skimage.viewer.plugins.base import Plugin
|
||||
from skimage.viewer.qt import QtGui, QtCore
|
||||
from numpy.testing import assert_almost_equal, assert_equal
|
||||
from numpy.testing.decorators import skipif
|
||||
from skimage._shared.utils import all_warnings
|
||||
|
||||
|
||||
def get_image_viewer():
|
||||
@@ -99,10 +100,13 @@ def test_save_buttons():
|
||||
timer.singleShot(100, QtGui.QApplication.quit)
|
||||
|
||||
sv.save_to_stack()
|
||||
sv.save_to_file(filename)
|
||||
with all_warnings(): # precision loss
|
||||
sv.save_to_file(filename)
|
||||
|
||||
img = data.imread(filename)
|
||||
assert_almost_equal(img, img_as_uint(viewer.image))
|
||||
|
||||
with all_warnings(): # precision loss
|
||||
assert_almost_equal(img, img_as_uint(viewer.image))
|
||||
|
||||
img = io.pop()
|
||||
assert_almost_equal(img, viewer.image)
|
||||
|
||||
Reference in New Issue
Block a user