Added better tests and removed weak ones

This commit is contained in:
Ankit Agrawal
2013-04-22 14:38:56 +05:30
parent c9330ea186
commit e1c23ac08c
2 changed files with 38 additions and 20 deletions
+9 -9
View File
@@ -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
+29 -11
View File
@@ -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()