diff --git a/skimage/color/tests/test_colorconv.py b/skimage/color/tests/test_colorconv.py index 7f1d7c73..05ab6915 100644 --- a/skimage/color/tests/test_colorconv.py +++ b/skimage/color/tests/test_colorconv.py @@ -14,23 +14,27 @@ Authors import os.path import numpy as np -from numpy.testing import * +from numpy.testing import (assert_equal, + assert_almost_equal, + assert_array_almost_equal, + assert_raises, + TestCase, + ) from skimage import img_as_float, img_as_ubyte from skimage.io import imread -from skimage.color import ( - rgb2hsv, hsv2rgb, - rgb2xyz, xyz2rgb, - rgb2hed, hed2rgb, - separate_stains, - combine_stains, - rgb2rgbcie, rgbcie2rgb, - convert_colorspace, - rgb2grey, gray2rgb, - xyz2lab, lab2xyz, - lab2rgb, rgb2lab, - is_rgb, is_gray - ) +from skimage.color import (rgb2hsv, hsv2rgb, + rgb2xyz, xyz2rgb, + rgb2hed, hed2rgb, + separate_stains, + combine_stains, + rgb2rgbcie, rgbcie2rgb, + convert_colorspace, + rgb2grey, gray2rgb, + xyz2lab, lab2xyz, + lab2rgb, rgb2lab, + is_rgb, is_gray + ) from skimage import data_dir, data @@ -267,4 +271,5 @@ def test_is_rgb(): if __name__ == "__main__": + from numpy.testing import run_module_suite run_module_suite() diff --git a/skimage/feature/tests/test_hog.py b/skimage/feature/tests/test_hog.py index cfef2da0..b37513a5 100644 --- a/skimage/feature/tests/test_hog.py +++ b/skimage/feature/tests/test_hog.py @@ -4,7 +4,10 @@ from skimage import data from skimage import feature from skimage import img_as_float from skimage import draw -from numpy.testing import * +from numpy.testing import (assert_raises, + assert_almost_equal, + ) + def test_histogram_of_oriented_gradients(): img = img_as_float(data.lena()[:256, :].mean(axis=2)) @@ -14,16 +17,19 @@ def test_histogram_of_oriented_gradients(): assert len(fd) == 9 * (256 // 8) * (512 // 8) + def test_hog_image_size_cell_size_mismatch(): image = data.camera()[:150, :200] fd = feature.hog(image, orientations=9, pixels_per_cell=(8, 8), cells_per_block=(1, 1)) assert len(fd) == 9 * (150 // 8) * (200 // 8) + def test_hog_color_image_unsupported_error(): image = np.zeros((20, 20, 3)) assert_raises(ValueError, feature.hog, image) + def test_hog_basic_orientations_and_data_types(): # scenario: # 1) create image (with float values) where upper half is filled by zeros, bottom half by 100 @@ -90,6 +96,7 @@ def test_hog_basic_orientations_and_data_types(): assert_almost_equal(actual, desired, decimal=2) + def test_hog_orientations_circle(): # scenario: # 1) create image with blurred circle in the middle @@ -129,6 +136,7 @@ def test_hog_orientations_circle(): desired = np.mean(hog_matrix) assert_almost_equal(actual, desired, decimal=1) + if __name__ == '__main__': from numpy.testing import run_module_suite run_module_suite() diff --git a/skimage/graph/tests/test_heap.py b/skimage/graph/tests/test_heap.py index 8322fd4e..cf7e3d0b 100644 --- a/skimage/graph/tests/test_heap.py +++ b/skimage/graph/tests/test_heap.py @@ -1,5 +1,3 @@ -from numpy.testing import * - import time import random import skimage.graph.heap as heap @@ -49,4 +47,5 @@ def _test_heap(n, fast_update): return t1 - t0 if __name__ == "__main__": + from numpy.testing import run_module_suite run_module_suite() diff --git a/skimage/graph/tests/test_mcp.py b/skimage/graph/tests/test_mcp.py index e3fd45a0..a1021380 100644 --- a/skimage/graph/tests/test_mcp.py +++ b/skimage/graph/tests/test_mcp.py @@ -1,5 +1,7 @@ import numpy as np -from numpy.testing import * +from numpy.testing import (assert_array_equal, + assert_almost_equal, + ) import skimage.graph.mcp as mcp @@ -7,15 +9,6 @@ a = np.ones((8, 8), dtype=np.float32) a[1:-1, 1] = 0 a[1, 1:-1] = 0 -## array([[ 1., 1., 1., 1., 1., 1., 1., 1.], -## [ 1., 0., 0., 0., 0., 0., 0., 1.], -## [ 1., 0., 1., 1., 1., 1., 1., 1.], -## [ 1., 0., 1., 1., 1., 1., 1., 1.], -## [ 1., 0., 1., 1., 1., 1., 1., 1.], -## [ 1., 0., 1., 1., 1., 1., 1., 1.], -## [ 1., 0., 1., 1., 1., 1., 1., 1.], -## [ 1., 1., 1., 1., 1., 1., 1., 1.]], dtype=float32) - def test_basic(): m = mcp.MCP(a, fully_connected=True) diff --git a/skimage/io/tests/test_collection.py b/skimage/io/tests/test_collection.py index 2bbfefa7..f650daeb 100644 --- a/skimage/io/tests/test_collection.py +++ b/skimage/io/tests/test_collection.py @@ -2,7 +2,10 @@ import sys import os.path import numpy as np -from numpy.testing import * +from numpy.testing import (assert_raises, + assert_equal, + assert_array_almost_equal, + ) from numpy.testing.decorators import skipif from skimage import data_dir @@ -148,4 +151,5 @@ class TestMultiImage(): if __name__ == "__main__": + from numpy.testing import run_module_suite run_module_suite() diff --git a/skimage/io/tests/test_colormixer.py b/skimage/io/tests/test_colormixer.py index b9f362a2..392a7b5b 100644 --- a/skimage/io/tests/test_colormixer.py +++ b/skimage/io/tests/test_colormixer.py @@ -1,4 +1,8 @@ -from numpy.testing import * +from numpy.testing import (assert_array_equal, + assert_almost_equal, + assert_equal, + assert_array_almost_equal, + ) import numpy as np import skimage.io._plugins._colormixer as cm @@ -136,4 +140,5 @@ class TestColorMixer(object): if __name__ == "__main__": + from numpy.testing import run_module_suite run_module_suite() diff --git a/skimage/io/tests/test_pil.py b/skimage/io/tests/test_pil.py index a9d986d6..3e2f3dde 100644 --- a/skimage/io/tests/test_pil.py +++ b/skimage/io/tests/test_pil.py @@ -55,7 +55,6 @@ def test_imread_palette(): @skipif(not PIL_available) def test_palette_is_gray(): - from PIL import Image gray = Image.open(os.path.join(data_dir, 'palette_gray.png')) assert _palette_is_grayscale(gray) color = Image.open(os.path.join(data_dir, 'palette_color.png')) diff --git a/skimage/io/tests/test_simpleitk.py b/skimage/io/tests/test_simpleitk.py index 4bb2cc23..2d4bd84b 100644 --- a/skimage/io/tests/test_simpleitk.py +++ b/skimage/io/tests/test_simpleitk.py @@ -1,6 +1,5 @@ import os.path import numpy as np -from numpy.testing import * from numpy.testing.decorators import skipif from tempfile import NamedTemporaryFile @@ -90,4 +89,5 @@ class TestSave: yield self.roundtrip, dtype, x if __name__ == "__main__": + from numpy.testing import run_module_suite run_module_suite() diff --git a/skimage/measure/tests/test_find_contours.py b/skimage/measure/tests/test_find_contours.py index 11b9b443..da2497eb 100644 --- a/skimage/measure/tests/test_find_contours.py +++ b/skimage/measure/tests/test_find_contours.py @@ -1,5 +1,7 @@ import numpy as np -from numpy.testing import * +from numpy.testing import (assert_raises, + assert_array_equal, + ) from skimage.measure import find_contours @@ -7,15 +9,6 @@ a = np.ones((8, 8), dtype=np.float32) a[1:-1, 1] = 0 a[1, 1:-1] = 0 -## array([[ 1., 1., 1., 1., 1., 1., 1., 1.], -## [ 1., 0., 0., 0., 0., 0., 0., 1.], -## [ 1., 0., 1., 1., 1., 1., 1., 1.], -## [ 1., 0., 1., 1., 1., 1., 1., 1.], -## [ 1., 0., 1., 1., 1., 1., 1., 1.], -## [ 1., 0., 1., 1., 1., 1., 1., 1.], -## [ 1., 0., 1., 1., 1., 1., 1., 1.], -## [ 1., 1., 1., 1., 1., 1., 1., 1.]], dtype=float32) - x, y = np.mgrid[-1:1:5j, -1:1:5j] r = np.sqrt(x**2 + y**2) diff --git a/skimage/morphology/_skeletonize.py b/skimage/morphology/_skeletonize.py index e9818ea9..bd9f225c 100644 --- a/skimage/morphology/_skeletonize.py +++ b/skimage/morphology/_skeletonize.py @@ -84,14 +84,18 @@ def skeletonize(image): # look up table - there is one entry for each of the 2^8=256 possible # combinations of 8 binary neighbours. 1's, 2's and 3's are candidates # for removal at each iteration of the algorithm. - lut = [0,0,0,1,0,0,1,3,0,0,3,1,1,0,1,3,0,0,0,0,0,0,0,0,2,0,2,0,3,0,3,3, - 0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,3,0,2,2, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 2,0,0,0,0,0,0,0,2,0,0,0,2,0,0,0,3,0,0,0,0,0,0,0,3,0,0,0,3,0,2,0, - 0,0,3,1,0,0,1,3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,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diff --git a/skimage/morphology/tests/test_watershed.py b/skimage/morphology/tests/test_watershed.py index 46298ae5..82531713 100644 --- a/skimage/morphology/tests/test_watershed.py +++ b/skimage/morphology/tests/test_watershed.py @@ -296,27 +296,27 @@ class TestWatershed(unittest.TestCase): def test_watershed07(self): "A regression test of a competitive case that failed" - data = np.array([[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255], - [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255], - [255,255,255,255,255,204,204,204,204,204,204,255,255,255,255,255], - [255,255,255,204,204,183,153,153,153,153,183,204,204,255,255,255], - [255,255,204,183,153,141,111,103,103,111,141,153,183,204,255,255], - [255,255,204,153,111, 94, 72, 52, 52, 72, 94,111,153,204,255,255], - [255,255,204,153,111, 72, 39, 1, 1, 39, 72,111,153,204,255,255], - [255,255,204,183,141,111, 72, 39, 39, 72,111,141,183,204,255,255], - [255,255,255,204,183,141,111, 72, 72,111,141,183,204,255,255,255], - [255,255,255,255,204,183,141, 94, 94,141,183,204,255,255,255,255], - [255,255,255,255,255,204,153,103,103,153,204,255,255,255,255,255], - [255,255,255,255,204,183,141, 94, 94,141,183,204,255,255,255,255], - [255,255,255,204,183,141,111, 72, 72,111,141,183,204,255,255,255], - [255,255,204,183,141,111, 72, 39, 39, 72,111,141,183,204,255,255], - [255,255,204,153,111, 72, 39, 1, 1, 39, 72,111,153,204,255,255], - [255,255,204,153,111, 94, 72, 52, 52, 72, 94,111,153,204,255,255], - [255,255,204,183,153,141,111,103,103,111,141,153,183,204,255,255], - [255,255,255,204,204,183,153,153,153,153,183,204,204,255,255,255], - [255,255,255,255,255,204,204,204,204,204,204,255,255,255,255,255], - [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255], - [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]]) + data = np.array([[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], + [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], + [255, 255, 255, 255, 255, 204, 204, 204, 204, 204, 204, 255, 255, 255, 255, 255], + [255, 255, 255, 204, 204, 183, 153, 153, 153, 153, 183, 204, 204, 255, 255, 255], + [255, 255, 204, 183, 153, 141, 111, 103, 103, 111, 141, 153, 183, 204, 255, 255], + [255, 255, 204, 153, 111, 94, 72, 52, 52, 72, 94, 111, 153, 204, 255, 255], + [255, 255, 204, 153, 111, 72, 39, 1, 1, 39, 72, 111, 153, 204, 255, 255], + [255, 255, 204, 183, 141, 111, 72, 39, 39, 72, 111, 141, 183, 204, 255, 255], + [255, 255, 255, 204, 183, 141, 111, 72, 72, 111, 141, 183, 204, 255, 255, 255], + [255, 255, 255, 255, 204, 183, 141, 94, 94, 141, 183, 204, 255, 255, 255, 255], + [255, 255, 255, 255, 255, 204, 153, 103, 103, 153, 204, 255, 255, 255, 255, 255], + [255, 255, 255, 255, 204, 183, 141, 94, 94, 141, 183, 204, 255, 255, 255, 255], + [255, 255, 255, 204, 183, 141, 111, 72, 72, 111, 141, 183, 204, 255, 255, 255], + [255, 255, 204, 183, 141, 111, 72, 39, 39, 72, 111, 141, 183, 204, 255, 255], + [255, 255, 204, 153, 111, 72, 39, 1, 1, 39, 72, 111, 153, 204, 255, 255], + [255, 255, 204, 153, 111, 94, 72, 52, 52, 72, 94, 111, 153, 204, 255, 255], + [255, 255, 204, 183, 153, 141, 111, 103, 103, 111, 141, 153, 183, 204, 255, 255], + [255, 255, 255, 204, 204, 183, 153, 153, 153, 153, 183, 204, 204, 255, 255, 255], + [255, 255, 255, 255, 255, 204, 204, 204, 204, 204, 204, 255, 255, 255, 255, 255], + [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], + [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]]) mask = (data != 255) markers = np.zeros(data.shape, int) markers[6, 7] = 1 @@ -332,27 +332,27 @@ class TestWatershed(unittest.TestCase): def test_watershed08(self): "The border pixels + an edge are all the same value" - data = np.array([[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255], - [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255], - [255,255,255,255,255,204,204,204,204,204,204,255,255,255,255,255], - [255,255,255,204,204,183,153,153,153,153,183,204,204,255,255,255], - [255,255,204,183,153,141,111,103,103,111,141,153,183,204,255,255], - [255,255,204,153,111, 94, 72, 52, 52, 72, 94,111,153,204,255,255], - [255,255,204,153,111, 72, 39, 1, 1, 39, 72,111,153,204,255,255], - [255,255,204,183,141,111, 72, 39, 39, 72,111,141,183,204,255,255], - [255,255,255,204,183,141,111, 72, 72,111,141,183,204,255,255,255], - [255,255,255,255,204,183,141, 94, 94,141,183,204,255,255,255,255], - [255,255,255,255,255,204,153,141,141,153,204,255,255,255,255,255], - [255,255,255,255,204,183,141, 94, 94,141,183,204,255,255,255,255], - [255,255,255,204,183,141,111, 72, 72,111,141,183,204,255,255,255], - [255,255,204,183,141,111, 72, 39, 39, 72,111,141,183,204,255,255], - [255,255,204,153,111, 72, 39, 1, 1, 39, 72,111,153,204,255,255], - [255,255,204,153,111, 94, 72, 52, 52, 72, 94,111,153,204,255,255], - [255,255,204,183,153,141,111,103,103,111,141,153,183,204,255,255], - [255,255,255,204,204,183,153,153,153,153,183,204,204,255,255,255], - [255,255,255,255,255,204,204,204,204,204,204,255,255,255,255,255], - [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255], - [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]]) + data = np.array([[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], + [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], + [255, 255, 255, 255, 255, 204, 204, 204, 204, 204, 204, 255, 255, 255, 255, 255], + [255, 255, 255, 204, 204, 183, 153, 153, 153, 153, 183, 204, 204, 255, 255, 255], + [255, 255, 204, 183, 153, 141, 111, 103, 103, 111, 141, 153, 183, 204, 255, 255], + [255, 255, 204, 153, 111, 94, 72, 52, 52, 72, 94, 111, 153, 204, 255, 255], + [255, 255, 204, 153, 111, 72, 39, 1, 1, 39, 72, 111, 153, 204, 255, 255], + [255, 255, 204, 183, 141, 111, 72, 39, 39, 72, 111, 141, 183, 204, 255, 255], + [255, 255, 255, 204, 183, 141, 111, 72, 72, 111, 141, 183, 204, 255, 255, 255], + [255, 255, 255, 255, 204, 183, 141, 94, 94, 141, 183, 204, 255, 255, 255, 255], + [255, 255, 255, 255, 255, 204, 153, 141, 141, 153, 204, 255, 255, 255, 255, 255], + [255, 255, 255, 255, 204, 183, 141, 94, 94, 141, 183, 204, 255, 255, 255, 255], + [255, 255, 255, 204, 183, 141, 111, 72, 72, 111, 141, 183, 204, 255, 255, 255], + [255, 255, 204, 183, 141, 111, 72, 39, 39, 72, 111, 141, 183, 204, 255, 255], + [255, 255, 204, 153, 111, 72, 39, 1, 1, 39, 72, 111, 153, 204, 255, 255], + [255, 255, 204, 153, 111, 94, 72, 52, 52, 72, 94, 111, 153, 204, 255, 255], + [255, 255, 204, 183, 153, 141, 111, 103, 103, 111, 141, 153, 183, 204, 255, 255], + [255, 255, 255, 204, 204, 183, 153, 153, 153, 153, 183, 204, 204, 255, 255, 255], + [255, 255, 255, 255, 255, 204, 204, 204, 204, 204, 204, 255, 255, 255, 255, 255], + [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], + [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]]) mask = (data != 255) markers = np.zeros(data.shape, int) markers[6, 7] = 1 diff --git a/skimage/transform/tests/test_finite_radon_transform.py b/skimage/transform/tests/test_finite_radon_transform.py index b5fcf43a..c4c4de7e 100644 --- a/skimage/transform/tests/test_finite_radon_transform.py +++ b/skimage/transform/tests/test_finite_radon_transform.py @@ -1,7 +1,6 @@ import numpy as np -from numpy.testing import * -from skimage.transform import * +from skimage.transform import frt2, ifrt2 def test_frt(): @@ -17,3 +16,8 @@ def test_frt(): f = frt2(L) fi = ifrt2(f) assert len(np.nonzero(L - fi)[0]) == 0 + +if __name__ == '__main__': + from numpy.testing import run_module_suite + run_module_suite() + diff --git a/skimage/transform/tests/test_integral.py b/skimage/transform/tests/test_integral.py index ed973cec..4a641e71 100644 --- a/skimage/transform/tests/test_integral.py +++ b/skimage/transform/tests/test_integral.py @@ -1,5 +1,5 @@ import numpy as np -from numpy.testing import * +from numpy.testing import assert_equal from skimage.transform import integral_image, integrate @@ -43,4 +43,5 @@ def test_vectorized_integrate(): if __name__ == '__main__': + from numpy.testing import run_module_suite run_module_suite() diff --git a/skimage/transform/tests/test_radon_transform.py b/skimage/transform/tests/test_radon_transform.py index c0fc883d..79cf80c5 100644 --- a/skimage/transform/tests/test_radon_transform.py +++ b/skimage/transform/tests/test_radon_transform.py @@ -181,4 +181,5 @@ def test_radon_iradon_circle(): if __name__ == "__main__": + from numpy.testing import run_module_suite run_module_suite()