From e1c23ac08c2ac3a956d75136ea63377e439ae867 Mon Sep 17 00:00:00 2001 From: Ankit Agrawal Date: Mon, 22 Apr 2013 14:38:56 +0530 Subject: [PATCH] Added better tests and removed weak ones --- skimage/exposure/exposure.py | 18 +++++------ skimage/exposure/tests/test_exposure.py | 40 ++++++++++++++++++------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/skimage/exposure/exposure.py b/skimage/exposure/exposure.py index 7537406c..ca8e99df 100644 --- a/skimage/exposure/exposure.py +++ b/skimage/exposure/exposure.py @@ -240,7 +240,7 @@ def rescale_intensity_gamma(image, gamma=1, gain=1): Notes ----- This function transforms the input image pixelwise according to the - equation O = I**gamma after scaling each pixel to the range 0 to 1. + equation ``O = I**gamma`` after scaling each pixel to the range 0 to 1. For gamma greater than 1, the histogram will shift towards left and the output image will be darker than the input image. @@ -250,7 +250,7 @@ def rescale_intensity_gamma(image, gamma=1, gain=1): References ---------- - ..[1] http://en.wikipedia.org/wiki/Gamma_correction + .. [1] http://en.wikipedia.org/wiki/Gamma_correction """ dtype = image.dtype.type @@ -284,12 +284,12 @@ def rescale_intensity_logarithmic(image, gain=1, inv=1): Notes ----- This function transforms the input image pixelwise according to the - equation O = gain*log(1 + I) after scaling each pixel to the range 0 to 1. - For inverse logarithmic correction, the equation is O = gain*(2**I - 1) + equation ``O = gain*log(1 + I)`` after scaling each pixel to the range 0 to 1. + For inverse logarithmic correction, the equation is ``O = gain*(2**I - 1)``. References ---------- - ..[1] http://www.ece.ucsb.edu/Faculty/Manjunath/courses/ece178W03/EnhancePart1.pdf + .. [1] http://www.ece.ucsb.edu/Faculty/Manjunath/courses/ece178W03/EnhancePart1.pdf """ dtype = image.dtype.type @@ -305,7 +305,7 @@ def rescale_intensity_logarithmic(image, gain=1, inv=1): def rescale_intensity_sigmoid(image, cutoff=0.5, gain=10): """Performs Sigmoid Correction on input image. - + Also known as Contrast Adjustment. Parameters @@ -326,12 +326,12 @@ def rescale_intensity_sigmoid(image, cutoff=0.5, gain=10): Notes ----- This function transforms the input image pixelwise according to the - equation O = 1/(1 + exp*(gain*(cutoff - I))) after scaling each pixel to - the range 0 to 1. + equation ``O = 1/(1 + exp*(gain*(cutoff - I)))`` after scaling each pixel + to the range 0 to 1. References ---------- - ..[1] http://bme.med.upatras.gr/improc/matalb_code_toc.htm#12. Adjust Contrast : + .. [1] http://bme.med.upatras.gr/improc/matalb_code_toc.htm#12. Adjust Contrast : """ dtype = image.dtype.type diff --git a/skimage/exposure/tests/test_exposure.py b/skimage/exposure/tests/test_exposure.py index bf7e1a24..0bd32812 100644 --- a/skimage/exposure/tests/test_exposure.py +++ b/skimage/exposure/tests/test_exposure.py @@ -217,35 +217,53 @@ def test_rescale_intensity_gamma_greater_one(): # =========================== def test_rescale_intensity_logarithmic(): - """Output's mean should be greater than input's mean for logarithmic - correction with multiplier constant equal to unity""" + """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() result = exposure.rescale_intensity_logarithmic(image, 1) assert result.mean() > image.mean() - + assert result.all() >= image.all() def test_rescale_intensity_inv_logarithmic(): - """Output's mean should be less than input's mean for inverse logarithmic - correction with multiplier constant equal to unity""" + """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() result = exposure.rescale_intensity_logarithmic(image, 1, -1) assert result.mean() < image.mean() + assert result.all() <= image.all() # Test Sigmoid Correction # ======================= def test_rescale_intensity_sigmoid_cutoff_one(): - """Output's mean should be less than input's mean for sigmoid - correction with cutoff equal to one and gain of 10""" + """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.mean() < image.mean() + assert result.std() < image.std() + assert result.all() <= image.all() def test_rescale_intensity_sigmoid_cutoff_zero(): - """Output's mean should be greater than input's mean for sigmoid - correction with cutoff equal to zero and gain of 10""" + """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() result = exposure.rescale_intensity_sigmoid(image, 0, 10) - assert result.mean() > image.mean() + assert result.std() < image.std() + assert result.all() >= image.all() + +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() + result = exposure.rescale_intensity_sigmoid(image, 0.5, 10) + assert result.std() > image.std()