diff --git a/skimage/exposure/tests/test_exposure.py b/skimage/exposure/tests/test_exposure.py index 0bd32812..b77f9a37 100644 --- a/skimage/exposure/tests/test_exposure.py +++ b/skimage/exposure/tests/test_exposure.py @@ -2,6 +2,7 @@ import warnings import numpy as np from numpy.testing import assert_array_almost_equal as assert_close +from numpy.testing import assert_array_equal import skimage from skimage import data from skimage import exposure @@ -184,8 +185,7 @@ def test_rescale_intensity_gamma_one(): """Same image should be returned for gamma equal to one""" image = data.camera() result = exposure.rescale_intensity_gamma(image, 1) - assert result.mean() == image.mean() - assert result.std() == image.std() + assert_array_equal(result, image) def test_rescale_intensity_gamma_zero(): @@ -198,72 +198,125 @@ def test_rescale_intensity_gamma_zero(): def test_rescale_intensity_gamma_less_one(): - """Output's mean should be greater than input's mean for gamma less than - one""" - image = data.camera() + """Verifying the output with expected results for gamma + correction with gamma equal to half""" + image = np.uint8(4 * np.arange(64).reshape(8,8)) + expected = np.array([[ 0, 31, 45, 55, 63, 71, 78, 84], + [ 90, 95, 100, 105, 110, 115, 119, 123], + [127, 131, 135, 139, 142, 146, 149, 153], + [156, 159, 162, 165, 168, 171, 174, 177], + [180, 183, 186, 188, 191, 194, 196, 199], + [201, 204, 206, 209, 211, 214, 216, 218], + [221, 223, 225, 228, 230, 232, 234, 236], + [238, 241, 243, 245, 247, 249, 251, 253]], dtype=np.uint8) + result = exposure.rescale_intensity_gamma(image, 0.5) - assert result.mean() > image.mean() + assert_array_equal(result, expected) def test_rescale_intensity_gamma_greater_one(): - """Output's mean should be less than input's mean for gamma greater than - one""" - image = data.camera() + """Verifying the output with expected results for gamma + correction with gamma equal to two""" + image = np.uint8(4 * np.arange(64).reshape(8,8)) + expected = np.array([[ 0, 0, 0, 0, 1, 1, 2, 3], + [ 4, 5, 6, 7, 9, 10, 12, 14], + [ 16, 18, 20, 22, 25, 27, 30, 33], + [ 36, 39, 42, 45, 49, 52, 56, 60], + [ 64, 68, 72, 76, 81, 85, 90, 95], + [100, 105, 110, 116, 121, 127, 132, 138], + [144, 150, 156, 163, 169, 176, 182, 189], + [196, 203, 211, 218, 225, 233, 241, 249]], dtype=np.uint8) + result = exposure.rescale_intensity_gamma(image, 2) - assert result.mean() < image.mean() + assert_array_equal(result, expected) # Test Logarithmic Correction # =========================== def test_rescale_intensity_logarithmic(): - """Output's mean should be greater than input's mean and all pixel values - in output should be either greater than or equal to that of corresponding - pixel in input for logarithmiccorrection with multiplier constant equal - to unity""" - image = data.camera() + """Verifying the output with expected results for logarithmic + correction with multiplier constant multiplier equal to unity""" + image = np.uint8(4 * np.arange(64).reshape(8,8)) + expected = np.array([[ 0, 5, 11, 16, 22, 27, 33, 38], + [ 43, 48, 53, 58, 63, 68, 73, 77], + [ 82, 86, 91, 95, 100, 104, 109, 113], + [117, 121, 125, 129, 133, 137, 141, 145], + [149, 153, 157, 160, 164, 168, 172, 175], + [179, 182, 186, 189, 193, 196, 199, 203], + [206, 209, 213, 216, 219, 222, 225, 228], + [231, 234, 238, 241, 244, 246, 249, 252]], dtype=np.uint8) + result = exposure.rescale_intensity_logarithmic(image, 1) - assert result.mean() > image.mean() - assert result.all() >= image.all() + assert_array_equal(result, expected) + def test_rescale_intensity_inv_logarithmic(): - """Output's mean should be less than input's mean and all pixel values - in output should be either less than or equal to that of corresponding - pixel in inputfor inverse logarithmic correction with multiplier constant - equal to unity""" - image = data.camera() + """Verifying the output with expected results for inverse logarithmic + correction with multiplier constant multiplier equal to unity""" + image = np.uint8(4 * np.arange(64).reshape(8,8)) + expected = np.array([[ 0, 2, 5, 8, 11, 14, 17, 20], + [ 23, 26, 29, 32, 35, 38, 41, 45], + [ 48, 51, 55, 58, 61, 65, 68, 72], + [ 76, 79, 83, 87, 90, 94, 98, 102], + [106, 110, 114, 118, 122, 126, 130, 134], + [138, 143, 147, 151, 156, 160, 165, 170], + [174, 179, 184, 188, 193, 198, 203, 208], + [213, 218, 224, 229, 234, 239, 245, 250]], dtype=np.uint8) + result = exposure.rescale_intensity_logarithmic(image, 1, -1) - assert result.mean() < image.mean() - assert result.all() <= image.all() + assert_array_equal(result, expected) # Test Sigmoid Correction # ======================= def test_rescale_intensity_sigmoid_cutoff_one(): - """Output's std should be less than input's std and all pixel values - in output should be either less than or equal to that of - corresponding pixel in input for sigmoid correction with cutoff equal - to one and gain of 10""" - image = data.camera() - result = exposure.rescale_intensity_sigmoid(image, 1, 10) - assert result.std() < image.std() - assert result.all() <= image.all() + """Verifying the output with expected results for sigmoid correction + with cutoff equal to one and gain of 5""" + image = np.uint8(4 * np.arange(64).reshape(8,8)) + expected = np.array([[ 1, 1, 1, 2, 2, 2, 2, 2], + [ 3, 3, 3, 4, 4, 4, 5, 5], + [ 5, 6, 6, 7, 7, 8, 9, 10], + [ 10, 11, 12, 13, 14, 15, 16, 18], + [ 19, 20, 22, 24, 25, 27, 29, 32], + [ 34, 36, 39, 41, 44, 47, 50, 54], + [ 57, 61, 64, 68, 72, 76, 80, 85], + [ 89, 94, 99, 104, 108, 113, 118, 123]], dtype=np.uint8) + + result = exposure.rescale_intensity_sigmoid(image, 1, 5) + assert_array_equal(result, expected) def test_rescale_intensity_sigmoid_cutoff_zero(): - """Output's std should be less than input's std and all pixel values - in output should be either greater than or equal to that of - corresponding pixel in input for sigmoid correction with cutoff equal - to zero and gain of 10""" - image = data.camera() + """Verifying the output with expected results for sigmoid correction + with cutoff equal to zero and gain of 10""" + image = np.uint8(4 * np.arange(64).reshape(8,8)) + expected = np.array([[127, 137, 147, 156, 166, 175, 183, 191], + [198, 205, 211, 216, 221, 225, 229, 232], + [235, 238, 240, 242, 244, 245, 247, 248], + [249, 250, 250, 251, 251, 252, 252, 253], + [253, 253, 253, 253, 254, 254, 254, 254], + [254, 254, 254, 254, 254, 254, 254, 254], + [254, 254, 254, 254, 254, 254, 254, 254], + [254, 254, 254, 254, 254, 254, 254, 254]], dtype=np.uint8) + result = exposure.rescale_intensity_sigmoid(image, 0, 10) - assert result.std() < image.std() - assert result.all() >= image.all() + assert_array_equal(result, expected) + def test_rescale_intensity_sigmoid_cutoff_half(): - """Output's std should be greater than input's std for sigmoid - correction with cutoff equal to 0.5 and gain of 10""" - image = data.camera() + """Verifying the output with expected results for sigmoid correction + with cutoff equal to half and gain of 10""" + image = np.uint8(4 * np.arange(64).reshape(8,8)) + expected = np.array([[ 1, 1, 2, 2, 3, 3, 4, 5], + [ 5, 6, 7, 9, 10, 12, 14, 16], + [ 19, 22, 25, 29, 34, 39, 44, 50], + [ 57, 64, 72, 80, 89, 99, 108, 118], + [128, 138, 148, 158, 167, 176, 184, 192], + [199, 205, 211, 217, 221, 226, 229, 233], + [236, 238, 240, 242, 244, 246, 247, 248], + [249, 250, 250, 251, 251, 252, 252, 253]], dtype=np.uint8) + result = exposure.rescale_intensity_sigmoid(image, 0.5, 10) - assert result.std() > image.std() + assert_array_equal(result, expected)