From 76f5156168dc5b7715380fa08917964cad38d5f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 15:21:26 +0200 Subject: [PATCH 01/18] Fix bug in warp which caused 1 pixel images not to be clipped --- skimage/transform/_geometric.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index 6e04a271..1179811d 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -1015,7 +1015,8 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1, if mode == 'constant' and not (0 <= cval <= 1): clipped[out == cval] = cval - if clipped.shape[0] == 1 or clipped.shape[1] == 1: + if clipped.ndim == 3 and orig_ndim == 2: + # remove singleton dim introduced by atleast_3d + return clipped[..., 0] + else: return clipped - else: # remove singleton dim introduced by atleast_3d - return clipped.squeeze() From 661d50ee205b3eed4728002c1e1d0bba8ad34383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 15:23:23 +0200 Subject: [PATCH 02/18] Full test coverage for image pyramids --- skimage/transform/tests/test_pyramids.py | 49 +++++++++++++++++++----- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/skimage/transform/tests/test_pyramids.py b/skimage/transform/tests/test_pyramids.py index 611ecdec..dd976a7b 100644 --- a/skimage/transform/tests/test_pyramids.py +++ b/skimage/transform/tests/test_pyramids.py @@ -1,41 +1,72 @@ -from numpy.testing import assert_array_equal, run_module_suite +from numpy.testing import assert_array_equal, assert_raises, run_module_suite from skimage import data -from skimage.transform import (pyramid_reduce, pyramid_expand, - pyramid_gaussian, pyramid_laplacian) +from skimage.transform import pyramids image = data.lena() +image_gray = image[..., 0] def test_pyramid_reduce(): + # RGB image rows, cols, dim = image.shape - out = pyramid_reduce(image, downscale=2) + out = pyramids.pyramid_reduce(image, downscale=2) assert_array_equal(out.shape, (rows / 2, cols / 2, dim)) + # grayscale image + rows, cols = image_gray.shape + out = pyramids.pyramid_reduce(image_gray, downscale=2) + assert_array_equal(out.shape, (rows / 2, cols / 2)) + def test_pyramid_expand(): + # RGB image rows, cols, dim = image.shape - out = pyramid_expand(image, upscale=2) + out = pyramids.pyramid_expand(image, upscale=2) assert_array_equal(out.shape, (rows * 2, cols * 2, dim)) + # grayscale image + rows, cols = image_gray.shape + out = pyramids.pyramid_expand(image_gray, upscale=2) + assert_array_equal(out.shape, (rows * 2, cols * 2)) + def test_build_gaussian_pyramid(): + # RGB image rows, cols, dim = image.shape - pyramid = pyramid_gaussian(image, downscale=2) - + pyramid = pyramids.pyramid_gaussian(image, downscale=2) for layer, out in enumerate(pyramid): layer_shape = (rows / 2 ** layer, cols / 2 ** layer, dim) assert_array_equal(out.shape, layer_shape) + # grayscale image + rows, cols = image_gray.shape + pyramid = pyramids.pyramid_gaussian(image_gray, downscale=2) + for layer, out in enumerate(pyramid): + layer_shape = (rows / 2 ** layer, cols / 2 ** layer) + assert_array_equal(out.shape, layer_shape) + def test_build_laplacian_pyramid(): + # RGB image rows, cols, dim = image.shape - pyramid = pyramid_laplacian(image, downscale=2) - + pyramid = pyramids.pyramid_laplacian(image, downscale=2) for layer, out in enumerate(pyramid): layer_shape = (rows / 2 ** layer, cols / 2 ** layer, dim) assert_array_equal(out.shape, layer_shape) + # grayscale image + rows, cols = image_gray.shape + pyramid = pyramids.pyramid_laplacian(image_gray, downscale=2) + for layer, out in enumerate(pyramid): + layer_shape = (rows / 2 ** layer, cols / 2 ** layer) + assert_array_equal(out.shape, layer_shape) + + +def test_check_factor(): + assert_raises(ValueError, pyramids._check_factor, 0.99) + assert_raises(ValueError, pyramids._check_factor, - 2) + if __name__ == "__main__": run_module_suite() From 59d3d842be3ae6082cc894300283cfcf6afde727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 17:43:20 +0200 Subject: [PATCH 03/18] Full test coveragem for data package --- skimage/data/tests/test_data.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/skimage/data/tests/test_data.py b/skimage/data/tests/test_data.py index 1d85802b..b5f6bcaa 100644 --- a/skimage/data/tests/test_data.py +++ b/skimage/data/tests/test_data.py @@ -15,9 +15,25 @@ def test_camera(): def test_checkerboard(): - """ Test that checkerboard image can be loaded. """ + """ Test that "checkerboard" image can be loaded. """ data.checkerboard() + +def test_text(): + """ Test that "text" image can be loaded. """ + data.text() + + +def test_moon(): + """ Test that "moon" image can be loaded. """ + data.moon() + + +def test_page(): + """ Test that "page" image can be loaded. """ + data.page() + + if __name__ == "__main__": from numpy.testing import run_module_suite run_module_suite() From 01df23a67d7aedd0ee503c926b1ba8009dbd2278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 17:47:54 +0200 Subject: [PATCH 04/18] Full test coverage for canny filter --- skimage/filter/tests/test_canny.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/skimage/filter/tests/test_canny.py b/skimage/filter/tests/test_canny.py index 1e406008..2c758edf 100644 --- a/skimage/filter/tests/test_canny.py +++ b/skimage/filter/tests/test_canny.py @@ -61,3 +61,8 @@ class TestCanny(unittest.TestCase): def test_image_shape(self): self.assertRaises(TypeError, F.canny, np.zeros((20, 20, 20)), 4, 0, 0) + + def test_mask_none(self): + result1 = F.canny(np.zeros((20, 20)), 4, 0, 0, np.ones((20, 20), bool)) + result2 = F.canny(np.zeros((20, 20)), 4, 0, 0) + self.assertTrue(np.all(result1 == result2)) From bca962cc8ad765d0e3b8bd97ddd1b025dc827735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 17:59:55 +0200 Subject: [PATCH 05/18] Improve test coverage for ctmf --- skimage/filter/tests/test_ctmf.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/skimage/filter/tests/test_ctmf.py b/skimage/filter/tests/test_ctmf.py index fd820469..c4f6d10e 100644 --- a/skimage/filter/tests/test_ctmf.py +++ b/skimage/filter/tests/test_ctmf.py @@ -117,5 +117,11 @@ def test_insufficient_size(): median_filter(img, radius=1) +@raises(TypeError) +def test_wrong_shape(): + img = np.empty((10, 10, 3)) + median_filter(img) + + if __name__ == "__main__": np.testing.run_module_suite() From fad2813dd8e6fb50e6552a5fbadf1b5e9635f267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 18:01:40 +0200 Subject: [PATCH 06/18] Fix callable test in LPI filter --- skimage/filter/lpi_filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/filter/lpi_filter.py b/skimage/filter/lpi_filter.py index 3826f5e7..2af74d7a 100644 --- a/skimage/filter/lpi_filter.py +++ b/skimage/filter/lpi_filter.py @@ -75,7 +75,7 @@ class LPIFilter2D(object): >>> filter = LPIFilter2D(filt_func) """ - if impulse_response is None: + if not callable(impulse_response): raise ValueError("Impulse response must be a callable.") self.impulse_response = impulse_response From 00dbb5e4e3017514f41ecbd40b00cfc53ec11916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 18:36:15 +0200 Subject: [PATCH 07/18] Improve test coverage of LPI filter --- skimage/filter/tests/test_lpi_filter.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/skimage/filter/tests/test_lpi_filter.py b/skimage/filter/tests/test_lpi_filter.py index 08e46a58..f6176691 100644 --- a/skimage/filter/tests/test_lpi_filter.py +++ b/skimage/filter/tests/test_lpi_filter.py @@ -8,7 +8,8 @@ from skimage.io import * from skimage.filter import * -class TestLPIFilter2D(): +class TestLPIFilter2D(object): + img = imread(os.path.join(data_dir, 'camera.png'), flatten=True)[:50, :50] @@ -55,5 +56,9 @@ class TestLPIFilter2D(): g1 = wiener(F[::-1, ::-1], self.filt_func) assert ((g - g1[::-1, ::-1]).sum() < 1) + def test_non_callable(self): + assert_raises(ValueError, LPIFilter2D, None) + + if __name__ == "__main__": run_module_suite() From d1629aec0f1a861106d54cb015b238e7fe542936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 19:05:11 +0200 Subject: [PATCH 08/18] Fix polygon approximation for 0 or less tolerance --- skimage/measure/_polygon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/measure/_polygon.py b/skimage/measure/_polygon.py index add4b5fb..7b9b920b 100644 --- a/skimage/measure/_polygon.py +++ b/skimage/measure/_polygon.py @@ -28,7 +28,7 @@ def approximate_polygon(coords, tolerance): ---------- .. [1] http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm """ - if tolerance == 0: + if tolerance <= 0: return coords chain = np.zeros(coords.shape[0], 'bool') From bee7223481e6899900087736132da7542a2eea58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 19:06:17 +0200 Subject: [PATCH 09/18] Full test coverage for polygon approximation and subdivision --- skimage/measure/tests/test_polygon.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/skimage/measure/tests/test_polygon.py b/skimage/measure/tests/test_polygon.py index 1907d7cb..c96aed88 100644 --- a/skimage/measure/tests/test_polygon.py +++ b/skimage/measure/tests/test_polygon.py @@ -22,6 +22,8 @@ def test_approximate_polygon(): out = approximate_polygon(square, -1) np.testing.assert_array_equal(out, square) + out = approximate_polygon(square, 0) + np.testing.assert_array_equal(out, square) def test_subdivide_polygon(): @@ -51,6 +53,10 @@ def test_subdivide_polygon(): np.testing.assert_equal(new_square3.shape[0], 2 * (square3.shape[0] - mask_len + 2)) + # not supported B-Spline degree + np.testing.assert_raises(ValueError, subdivide_polygon, square, 0) + np.testing.assert_raises(ValueError, subdivide_polygon, square, 8) + if __name__ == "__main__": np.testing.run_module_suite() From db76b212c736041ed2f6da9ec4bf70993a72bd63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 19:23:58 +0200 Subject: [PATCH 10/18] Full test coverage for regionprops --- skimage/measure/tests/test_regionprops.py | 31 ++++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/skimage/measure/tests/test_regionprops.py b/skimage/measure/tests/test_regionprops.py index 271c1ec4..524f55ee 100644 --- a/skimage/measure/tests/test_regionprops.py +++ b/skimage/measure/tests/test_regionprops.py @@ -1,9 +1,9 @@ from numpy.testing import assert_array_equal, assert_almost_equal, \ - assert_array_almost_equal + assert_array_almost_equal, assert_raises import numpy as np import math -from skimage.measure import regionprops +from skimage.measure._regionprops import regionprops, PROPS, perimeter SAMPLE = np.array( @@ -22,6 +22,16 @@ INTENSITY_SAMPLE = SAMPLE.copy() INTENSITY_SAMPLE[1, 9:11] = 2 +def test_unsupported_dtype(): + assert_raises(TypeError, regionprops, np.zeros((10, 10), dtype=np.double)) + + +def test_all_props(): + props = regionprops(SAMPLE, 'all', INTENSITY_SAMPLE)[0] + for prop in PROPS: + assert prop in props + + def test_area(): area = regionprops(SAMPLE, ['Area'])[0]['Area'] assert area == np.sum(SAMPLE) @@ -90,6 +100,11 @@ def test_eccentricity(): eps = regionprops(SAMPLE, ['Eccentricity'])[0]['Eccentricity'] assert_almost_equal(eps, 0.814629313427) + img = np.zeros((5, 5), dtype=np.int) + img[2, 2] = 1 + eps = regionprops(img, ['Eccentricity'])[0]['Eccentricity'] + assert_almost_equal(eps, 0) + def test_equiv_diameter(): diameter = regionprops(SAMPLE, ['EquivDiameter'])[0]['EquivDiameter'] @@ -142,6 +157,11 @@ def test_filled_area(): assert area == np.sum(SAMPLE) +def test_filled_image(): + img = regionprops(SAMPLE, ['FilledImage'])[0]['FilledImage'] + assert_array_equal(img, SAMPLE) + + def test_major_axis_length(): length = regionprops(SAMPLE, ['MajorAxisLength'])[0]['MajorAxisLength'] # MATLAB has different interpretation of ellipse than found in literature, @@ -220,8 +240,11 @@ def test_orientation(): assert_almost_equal(orientation_diag, -math.pi / 4) def test_perimeter(): - perimeter = regionprops(SAMPLE, ['Perimeter'])[0]['Perimeter'] - assert_almost_equal(perimeter, 59.2132034355964) + per = regionprops(SAMPLE, ['Perimeter'])[0]['Perimeter'] + assert_almost_equal(per, 59.2132034355964) + + per = perimeter(SAMPLE, neighbourhood=8) + assert_almost_equal(per, 43.1213203436) def test_solidity(): solidity = regionprops(SAMPLE, ['Solidity'])[0]['Solidity'] From aa85b22f6da450d258931efec8f87ac5165cdb29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 19:36:09 +0200 Subject: [PATCH 11/18] Full test coverage for structural similarity --- .../tests/test_structural_similarity.py | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/skimage/measure/tests/test_structural_similarity.py b/skimage/measure/tests/test_structural_similarity.py index 3eb2a7e9..d2ddc774 100644 --- a/skimage/measure/tests/test_structural_similarity.py +++ b/skimage/measure/tests/test_structural_similarity.py @@ -1,5 +1,5 @@ import numpy as np -from numpy.testing import assert_equal +from numpy.testing import assert_equal, assert_raises from skimage.measure import structural_similarity as ssim @@ -24,20 +24,18 @@ def test_ssim_image(): S1 = ssim(X, Y, win_size=3) assert(S1 < 0.3) -## Come up with a better way of testing the gradient -## -## def test_ssim_grad(): -## N = 30 -## X = np.random.random((N, N)) * 255 -## Y = np.random.random((N, N)) * 255 -## def func(Y): -## return ssim(X, Y, dynamic_range=255) +def test_ssim_grad(): + N = 30 + X = np.random.random((N, N)) * 255 + Y = np.random.random((N, N)) * 255 -## def grad(Y): -## return ssim(X, Y, dynamic_range=255, gradient=True)[1] + f = ssim(X, Y, dynamic_range=255) + g = ssim(X, Y, dynamic_range=255, gradient=True) -## assert(np.all(opt.check_grad(func, grad, Y) < 0.05)) + assert f < 0.05 + assert g[0] < 0.05 + assert np.all(g[1] < 0.05) def test_ssim_dtype(): @@ -56,5 +54,15 @@ def test_ssim_dtype(): assert S2 < 0.1 +def test_invalid_input(): + X = np.zeros((3, 3), dtype=np.double) + Y = np.zeros((3, 3), dtype=np.int) + assert_raises(ValueError, ssim, X, Y) + + Y = np.zeros((4, 4), dtype=np.double) + assert_raises(ValueError, ssim, X, Y) + + assert_raises(ValueError, ssim, X, X, win_size=8) + if __name__ == "__main__": np.testing.run_module_suite() From 5117803b79ee56b412f550123e158507f759599c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 21:34:41 +0200 Subject: [PATCH 12/18] Improve test coverage of find_contours --- skimage/measure/find_contours.py | 2 +- skimage/measure/tests/test_find_contours.py | 62 ++++++++++++--------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/skimage/measure/find_contours.py b/skimage/measure/find_contours.py index 68e1d53c..eafbd523 100755 --- a/skimage/measure/find_contours.py +++ b/skimage/measure/find_contours.py @@ -98,7 +98,7 @@ def find_contours(array, level, """ array = np.asarray(array, dtype=np.double) if array.ndim != 2: - raise RuntimeError('Only 2D arrays are supported.') + raise TypeError('Only 2D arrays are supported.') level = float(level) if (fully_connected not in _param_options or positive_orientation not in _param_options): diff --git a/skimage/measure/tests/test_find_contours.py b/skimage/measure/tests/test_find_contours.py index 62b39b3f..cde60e4d 100644 --- a/skimage/measure/tests/test_find_contours.py +++ b/skimage/measure/tests/test_find_contours.py @@ -21,34 +21,37 @@ r = np.sqrt(x**2 + y**2) def test_binary(): - contours = find_contours(a, 0.5) + ref = [[6. , 1.5], + [5. , 1.5], + [4. , 1.5], + [3. , 1.5], + [2. , 1.5], + [1.5, 2. ], + [1.5, 3. ], + [1.5, 4. ], + [1.5, 5. ], + [1.5, 6. ], + [1. , 6.5], + [0.5, 6. ], + [0.5, 5. ], + [0.5, 4. ], + [0.5, 3. ], + [0.5, 2. ], + [0.5, 1. ], + [1. , 0.5], + [2. , 0.5], + [3. , 0.5], + [4. , 0.5], + [5. , 0.5], + [6. , 0.5], + [6.5, 1. ], + [6. , 1.5]] + + contours = find_contours(a, 0.5, positive_orientation='high') assert len(contours) == 1 - assert_array_equal(contours[0], - [[6. , 1.5], - [5. , 1.5], - [4. , 1.5], - [3. , 1.5], - [2. , 1.5], - [1.5, 2. ], - [1.5, 3. ], - [1.5, 4. ], - [1.5, 5. ], - [1.5, 6. ], - [1. , 6.5], - [0.5, 6. ], - [0.5, 5. ], - [0.5, 4. ], - [0.5, 3. ], - [0.5, 2. ], - [0.5, 1. ], - [1. , 0.5], - [2. , 0.5], - [3. , 0.5], - [4. , 0.5], - [5. , 0.5], - [6. , 0.5], - [6.5, 1. ], - [6. , 1.5]]) + assert_array_equal(contours[0][::-1], ref) + + def test_float(): @@ -70,6 +73,11 @@ def test_memory_order(): assert len(contours) == 1 +def test_invalid_input(): + assert_raises(ValueError, find_contours, r, 0.5, 'foo', 'bar') + assert_raises(TypeError, find_contours, r[..., None], 0.5) + + if __name__ == '__main__': from numpy.testing import run_module_suite run_module_suite() From 48572fd0a3dfa90404b69916a97cb66a51e44c58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 21:52:15 +0200 Subject: [PATCH 13/18] Remove obsolete license note as code has been refactored --- skimage/morphology/grey.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/skimage/morphology/grey.py b/skimage/morphology/grey.py index e7e52de4..47ef1d2c 100644 --- a/skimage/morphology/grey.py +++ b/skimage/morphology/grey.py @@ -1,10 +1,3 @@ -""" -:author: Damian Eads, 2009 -:license: modified BSD -""" - -__docformat__ = 'restructuredtext en' - import warnings from skimage import img_as_ubyte From 0ab93bbf366d0e938625cadb775180a6496dd80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 21:54:12 +0200 Subject: [PATCH 14/18] Remove redundant dtype conversion --- skimage/morphology/grey.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/skimage/morphology/grey.py b/skimage/morphology/grey.py index 47ef1d2c..69050773 100644 --- a/skimage/morphology/grey.py +++ b/skimage/morphology/grey.py @@ -254,7 +254,6 @@ def white_tophat(image, selem, out=None): """ if image is out: raise NotImplementedError("Cannot perform white top hat in place.") - image = img_as_ubyte(image) out = opening(image, selem, out=out) out = image - out @@ -304,7 +303,6 @@ def black_tophat(image, selem, out=None): if image is out: raise NotImplementedError("Cannot perform white top hat in place.") - image = img_as_ubyte(image) out = closing(image, selem, out=out) out = out - image From 2c36d34f9a109378fca0535027d5768c91582087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Mon, 8 Oct 2012 10:55:19 +0200 Subject: [PATCH 15/18] Change Exception type for wrong input dims --- skimage/measure/find_contours.py | 2 +- skimage/measure/tests/test_find_contours.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/skimage/measure/find_contours.py b/skimage/measure/find_contours.py index eafbd523..3a546ccf 100755 --- a/skimage/measure/find_contours.py +++ b/skimage/measure/find_contours.py @@ -98,7 +98,7 @@ def find_contours(array, level, """ array = np.asarray(array, dtype=np.double) if array.ndim != 2: - raise TypeError('Only 2D arrays are supported.') + raise ValueError('Only 2D arrays are supported.') level = float(level) if (fully_connected not in _param_options or positive_orientation not in _param_options): diff --git a/skimage/measure/tests/test_find_contours.py b/skimage/measure/tests/test_find_contours.py index cde60e4d..11b9b443 100644 --- a/skimage/measure/tests/test_find_contours.py +++ b/skimage/measure/tests/test_find_contours.py @@ -75,7 +75,7 @@ def test_memory_order(): def test_invalid_input(): assert_raises(ValueError, find_contours, r, 0.5, 'foo', 'bar') - assert_raises(TypeError, find_contours, r[..., None], 0.5) + assert_raises(ValueError, find_contours, r[..., None], 0.5) if __name__ == '__main__': From 48210ecb389e6a6b94b58700863298b9f5e7a719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 9 Oct 2012 07:53:54 +0200 Subject: [PATCH 16/18] Add note about random test failure for some systems --- skimage/measure/tests/test_structural_similarity.py | 1 + 1 file changed, 1 insertion(+) diff --git a/skimage/measure/tests/test_structural_similarity.py b/skimage/measure/tests/test_structural_similarity.py index d2ddc774..ac45072a 100644 --- a/skimage/measure/tests/test_structural_similarity.py +++ b/skimage/measure/tests/test_structural_similarity.py @@ -25,6 +25,7 @@ def test_ssim_image(): assert(S1 < 0.3) +# NOTE: This test is known to randomly fail on some systems (Mac OS X 10.6) def test_ssim_grad(): N = 30 X = np.random.random((N, N)) * 255 From e47411ed4c13379fd648eff0c459c79c57790f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 9 Oct 2012 08:02:43 +0200 Subject: [PATCH 17/18] Split tests for different channel numbers into separate functions --- skimage/transform/tests/test_pyramids.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/skimage/transform/tests/test_pyramids.py b/skimage/transform/tests/test_pyramids.py index dd976a7b..6d0609e0 100644 --- a/skimage/transform/tests/test_pyramids.py +++ b/skimage/transform/tests/test_pyramids.py @@ -7,39 +7,39 @@ image = data.lena() image_gray = image[..., 0] -def test_pyramid_reduce(): - # RGB image +def test_pyramid_reduce_rgb(): rows, cols, dim = image.shape out = pyramids.pyramid_reduce(image, downscale=2) assert_array_equal(out.shape, (rows / 2, cols / 2, dim)) - # grayscale image + +def test_pyramid_reduce_gray(): rows, cols = image_gray.shape out = pyramids.pyramid_reduce(image_gray, downscale=2) assert_array_equal(out.shape, (rows / 2, cols / 2)) -def test_pyramid_expand(): - # RGB image +def test_pyramid_expand_rgb(): rows, cols, dim = image.shape out = pyramids.pyramid_expand(image, upscale=2) assert_array_equal(out.shape, (rows * 2, cols * 2, dim)) - # grayscale image + +def test_pyramid_expand_gray(): rows, cols = image_gray.shape out = pyramids.pyramid_expand(image_gray, upscale=2) assert_array_equal(out.shape, (rows * 2, cols * 2)) -def test_build_gaussian_pyramid(): - # RGB image +def test_build_gaussian_pyramid_rgb(): rows, cols, dim = image.shape pyramid = pyramids.pyramid_gaussian(image, downscale=2) for layer, out in enumerate(pyramid): layer_shape = (rows / 2 ** layer, cols / 2 ** layer, dim) assert_array_equal(out.shape, layer_shape) - # grayscale image + +def test_build_gaussian_pyramid_gray(): rows, cols = image_gray.shape pyramid = pyramids.pyramid_gaussian(image_gray, downscale=2) for layer, out in enumerate(pyramid): @@ -47,15 +47,15 @@ def test_build_gaussian_pyramid(): assert_array_equal(out.shape, layer_shape) -def test_build_laplacian_pyramid(): - # RGB image +def test_build_laplacian_pyramid_rgb(): rows, cols, dim = image.shape pyramid = pyramids.pyramid_laplacian(image, downscale=2) for layer, out in enumerate(pyramid): layer_shape = (rows / 2 ** layer, cols / 2 ** layer, dim) assert_array_equal(out.shape, layer_shape) - # grayscale image + +def test_build_laplacian_pyramid_gray(): rows, cols = image_gray.shape pyramid = pyramids.pyramid_laplacian(image_gray, downscale=2) for layer, out in enumerate(pyramid): From dc0d4eff74a019bd777e44892659c7b7da3fe56d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 9 Oct 2012 08:04:25 +0200 Subject: [PATCH 18/18] Add missing empty lines between test functions --- skimage/measure/tests/test_regionprops.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/skimage/measure/tests/test_regionprops.py b/skimage/measure/tests/test_regionprops.py index 524f55ee..6c7f5d46 100644 --- a/skimage/measure/tests/test_regionprops.py +++ b/skimage/measure/tests/test_regionprops.py @@ -46,6 +46,7 @@ def test_bbox(): bbox = regionprops(SAMPLE_mod, ['BoundingBox'])[0]['BoundingBox'] assert_array_almost_equal(bbox, (0, 0, SAMPLE.shape[0], SAMPLE.shape[1]-1)) + def test_central_moments(): mu = regionprops(SAMPLE, ['CentralMoments'])[0]['CentralMoments'] #: determined with OpenCV @@ -58,6 +59,7 @@ def test_central_moments(): assert_almost_equal(mu[2,1], 2000.296296296291) assert_almost_equal(mu[3,0], -760.0246913580195) + def test_centroid(): centroid = regionprops(SAMPLE, ['Centroid'])[0]['Centroid'] # determined with MATLAB @@ -208,6 +210,7 @@ def test_moments(): assert_almost_equal(m[2,1], 43882.0) assert_almost_equal(m[3,0], 95588.0) + def test_normalized_moments(): nu = regionprops(SAMPLE, ['NormalizedMoments'])[0]['NormalizedMoments'] #: determined with OpenCV @@ -218,6 +221,7 @@ def test_normalized_moments(): assert_almost_equal(nu[2,1], 0.045473992910668816) assert_almost_equal(nu[3,0], -0.017278118992041805) + def test_orientation(): orientation = regionprops(SAMPLE, ['Orientation'])[0]['Orientation'] # determined with MATLAB @@ -239,6 +243,7 @@ def test_orientation(): )[0]['Orientation'] assert_almost_equal(orientation_diag, -math.pi / 4) + def test_perimeter(): per = regionprops(SAMPLE, ['Perimeter'])[0]['Perimeter'] assert_almost_equal(per, 59.2132034355964) @@ -246,11 +251,13 @@ def test_perimeter(): per = perimeter(SAMPLE, neighbourhood=8) assert_almost_equal(per, 43.1213203436) + def test_solidity(): solidity = regionprops(SAMPLE, ['Solidity'])[0]['Solidity'] # determined with MATLAB assert_almost_equal(solidity, 0.580645161290323) + def test_weighted_central_moments(): wmu = regionprops(SAMPLE, ['WeightedCentralMoments'], INTENSITY_SAMPLE )[0]['WeightedCentralMoments'] @@ -304,6 +311,7 @@ def test_weighted_moments(): ) assert_array_almost_equal(wm, ref) + def test_weighted_normalized_moments(): wnu = regionprops(SAMPLE, ['WeightedNormalizedMoments'], INTENSITY_SAMPLE )[0]['WeightedNormalizedMoments'] @@ -315,6 +323,7 @@ def test_weighted_normalized_moments(): ) assert_array_almost_equal(wnu, ref) + if __name__ == "__main__": from numpy.testing import run_module_suite run_module_suite()