Minor improvements in docs, tests

This commit is contained in:
Ankit Agrawal
2013-06-06 12:12:40 +08:00
parent a475d3c694
commit 23f61795eb
2 changed files with 32 additions and 21 deletions
+11 -17
View File
@@ -222,6 +222,8 @@ def rescale_intensity_gamma(image, gamma=1, gain=1):
"""Performs Gamma Correction on the input image.
Also known as Power Law Transform.
This function transforms the input image pixelwise according to the
equation ``O = I**gamma`` after scaling each pixel to the range 0 to 1.
Parameters
----------
@@ -239,9 +241,6 @@ 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.
For gamma greater than 1, the histogram will shift towards left and
the output image will be darker than the input image.
@@ -266,6 +265,10 @@ def rescale_intensity_gamma(image, gamma=1, gain=1):
def rescale_intensity_log(image, gain=1, inv=False):
"""Performs Logarithmic correction on the input image.
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)``.
Parameters
----------
image : ndarray
@@ -281,12 +284,6 @@ def rescale_intensity_log(image, gain=1, inv=False):
out : ndarray
Logarithm corrected output image.
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)``.
References
----------
.. [1] http://www.ece.ucsb.edu/Faculty/Manjunath/courses/ece178W03/EnhancePart1.pdf
@@ -304,9 +301,12 @@ def rescale_intensity_log(image, gain=1, inv=False):
def rescale_intensity_sigmoid(image, cutoff=0.5, gain=10, inv=False):
"""Performs Sigmoid Correction on input image.
"""Performs Sigmoid Correction on the input image.
Also known as Contrast Adjustment.
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.
Parameters
----------
@@ -325,12 +325,6 @@ def rescale_intensity_sigmoid(image, cutoff=0.5, gain=10, inv=False):
out : ndarray
Sigmoid corrected output image.
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.
References
----------
.. [1] http://bme.med.upatras.gr/improc/matalb_code_toc.htm#12. Adjust Contrast :
@@ -339,7 +333,7 @@ def rescale_intensity_sigmoid(image, cutoff=0.5, gain=10, inv=False):
dtype = image.dtype.type
scale = float(dtype_range[dtype][1] - dtype_range[dtype][0])
if inv == True:
out = 1 - (1 / (1 + np.exp(gain * (cutoff - image/scale)))) * scale
out = (1 - 1 / (1 + np.exp(gain * (cutoff - image/scale)))) * scale
return dtype(out)
out = (1 / (1 + np.exp(gain * (cutoff - image/scale)))) * scale
return dtype(out)
+21 -4
View File
@@ -183,14 +183,14 @@ if __name__ == '__main__':
def test_rescale_intensity_gamma_one():
"""Same image should be returned for gamma equal to one"""
image = np.random.random((8, 8))
image = np.arange(0, 255, 4, np.uint8).reshape(8,8)
result = exposure.rescale_intensity_gamma(image, 1)
assert_array_equal(result, image)
def test_rescale_intensity_gamma_zero():
"""White image should be returned for gamma equal to zero"""
image = np.random.random((8, 8))
image = np.arange(0, 255, 4, np.uint8).reshape(8,8)
result = exposure.rescale_intensity_gamma(image, 0)
dtype = image.dtype.type
assert_array_equal(result, dtype_range[dtype][1])
@@ -233,7 +233,7 @@ def test_rescale_intensity_gamma_greater_one():
# Test Logarithmic Correction
# ===========================
def test_rescale_intensity_logarithmic():
def test_rescale_intensity_log():
"""Verifying the output with expected results for logarithmic
correction with multiplier constant multiplier equal to unity"""
image = np.arange(0, 255, 4, np.uint8).reshape(8,8)
@@ -250,7 +250,7 @@ def test_rescale_intensity_logarithmic():
assert_array_equal(result, expected)
def test_rescale_intensity_inv_logarithmic():
def test_rescale_intensity_inv_log():
"""Verifying the output with expected results for inverse logarithmic
correction with multiplier constant multiplier equal to unity"""
image = np.arange(0, 255, 4, np.uint8).reshape(8,8)
@@ -319,3 +319,20 @@ def test_rescale_intensity_sigmoid_cutoff_half():
result = exposure.rescale_intensity_sigmoid(image, 0.5, 10)
assert_array_equal(result, expected)
def test_rescale_intensity_inv_sigmoid_cutoff_half():
"""Verifying the output with expected results for inverse sigmoid
correction with cutoff equal to half and gain of 10"""
image = np.arange(0, 255, 4, np.uint8).reshape(8,8)
expected = np.array([[253, 253, 252, 252, 251, 251, 250, 249],
[249, 248, 247, 245, 244, 242, 240, 238],
[235, 232, 229, 225, 220, 215, 210, 204],
[197, 190, 182, 174, 165, 155, 146, 136],
[126, 116, 106, 96, 87, 78, 70, 62],
[ 55, 49, 43, 37, 33, 28, 25, 21],
[ 18, 16, 14, 12, 10, 8, 7, 6],
[ 5, 4, 4, 3, 3, 2, 2, 1]], dtype=np.uint8)
result = exposure.rescale_intensity_sigmoid(image, 0.5, 10, True)
assert_array_equal(result, expected)