diff --git a/skimage/measure/tests/test_blocks.py b/skimage/measure/tests/test_blocks.py index 77dc2b11..11894585 100644 --- a/skimage/measure/tests/test_blocks.py +++ b/skimage/measure/tests/test_blocks.py @@ -1,6 +1,7 @@ import numpy as np from numpy.testing import assert_array_equal -from skimage.measure import block_sum +from skimage.measure import (block_sum, block_mean, block_median, block_min, + block_max) def test_block_sum(): @@ -17,5 +18,65 @@ def test_block_sum(): assert_array_equal(expected2, out2) +def test_block_mean(): + image1 = np.arange(4 * 6).reshape(4, 6) + out1 = block_mean(image1, (2, 3)) + expected1 = np.array([[ 4., 7.], + [ 16., 19.]]) + assert_array_equal(expected1, out1) + + image2 = np.arange(5 * 8).reshape(5, 8) + out2 = block_mean(image2, (4, 5)) + expected2 = np.array([[14. , 10.8], + [ 8.5, 5.7]]) + assert_array_equal(expected2, out2) + + +def test_block_median(): + image1 = np.arange(4 * 6).reshape(4, 6) + out1 = block_median(image1, (2, 3)) + expected1 = np.array([[ 4., 7.], + [ 16., 19.]]) + assert_array_equal(expected1, out1) + + image2 = np.arange(5 * 8).reshape(5, 8) + out2 = block_median(image2, (4, 5)) + expected2 = np.array([[ 14., 17.], + [ 0., 0.]]) + assert_array_equal(expected2, out2) + + image3 = np.array([[1, 5, 5, 5], [5, 5, 5, 1000]]) + out3 = block_median(image3, (2, 4)) + assert_array_equal(5, out3) + + +def test_block_min(): + image1 = np.arange(4 * 6).reshape(4, 6) + out1 = block_min(image1, (2, 3)) + expected1 = np.array([[ 0, 3], + [12, 15]]) + assert_array_equal(expected1, out1) + + image2 = np.arange(5 * 8).reshape(5, 8) + out2 = block_min(image2, (4, 5)) + expected2 = np.array([[0, 0], + [0, 0]]) + assert_array_equal(expected2, out2) + + +def test_block_max(): + image1 = np.arange(4 * 6).reshape(4, 6) + out1 = block_max(image1, (2, 3)) + expected1 = np.array([[ 8, 11], + [20, 23]]) + assert_array_equal(expected1, out1) + + image2 = np.arange(5 * 8).reshape(5, 8) + out2 = block_max(image2, (4, 5)) + expected2 = np.array([[28, 31], + [36, 39]]) + assert_array_equal(expected2, out2) + + if __name__ == "__main__": np.testing.run_module_suite() diff --git a/skimage/transform/tests/test_warps.py b/skimage/transform/tests/test_warps.py index 272be66e..af2b95da 100644 --- a/skimage/transform/tests/test_warps.py +++ b/skimage/transform/tests/test_warps.py @@ -196,13 +196,13 @@ def test_warp_coords_example(): def test_downscale_local_mean(): - """Verifying downsampling of an array with expected result in mean mode""" - image1 = np.arange(4*6).reshape(4, 6) + image1 = np.arange(4 * 6).reshape(4, 6) out1 = downscale_local_mean(image1, (2, 3)) expected1 = np.array([[ 4., 7.], [ 16., 19.]]) assert_array_equal(expected1, out1) - image2 = np.arange(5*8).reshape(5, 8) + + image2 = np.arange(5 * 8).reshape(5, 8) out2 = downscale_local_mean(image2, (4, 5)) expected2 = np.array([[ 14. , 10.8], [ 8.5, 5.7]])