Renaming rescale_intensity_* as adjust_*

This commit is contained in:
Ankit Agrawal
2013-05-27 19:30:36 +08:00
parent 9a1c39f089
commit f94f3db597
2 changed files with 40 additions and 41 deletions
+20 -21
View File
@@ -9,8 +9,8 @@ from skimage._shared.utils import deprecated
__all__ = ['histogram', 'cumulative_distribution', 'equalize',
'rescale_intensity', 'rescale_intensity_gamma',
'rescale_intensity_log', 'rescale_intensity_sigmoid']
'rescale_intensity', 'adjust_gamma',
'adjust_log', 'adjust_sigmoid']
def histogram(image, nbins=256):
@@ -219,7 +219,7 @@ def rescale_intensity(image, in_range=None, out_range=None):
return dtype(image * (omax - omin) + omin)
def _assert_not_negative(image):
def _assert_non_negative(image):
if np.any(image < 0):
raise ValueError('Image Correction methods work correctly only on '
@@ -229,7 +229,7 @@ def _assert_not_negative(image):
return True
def rescale_intensity_gamma(image, gamma=1, gain=1):
def adjust_gamma(image, gamma=1, gain=1):
"""Performs Gamma Correction on the input image.
Also known as Power Law Transform.
@@ -263,19 +263,19 @@ def rescale_intensity_gamma(image, gamma=1, gain=1):
.. [1] http://en.wikipedia.org/wiki/Gamma_correction
"""
_assert_non_negative(image)
dtype = image.dtype.type
if gamma < 0:
return "Gamma should be a non-negative real number"
if _assert_not_negative(image):
scale = float(dtype_limits(image, True)[1] - dtype_limits(image, True)[0])
scale = float(dtype_limits(image, True)[1] - dtype_limits(image, True)[0])
out = ((image / scale) ** gamma) * scale * gain
return dtype(out)
def rescale_intensity_log(image, gain=1, inv=False):
def adjust_log(image, gain=1, inv=False):
"""Performs Logarithmic correction on the input image.
This function transforms the input image pixelwise according to the
@@ -302,20 +302,19 @@ def rescale_intensity_log(image, gain=1, inv=False):
.. [1] http://www.ece.ucsb.edu/Faculty/Manjunath/courses/ece178W03/EnhancePart1.pdf
"""
_assert_non_negative(image)
dtype = image.dtype.type
scale = float(dtype_limits(image, True)[1] - dtype_limits(image, True)[0])
if _assert_not_negative(image):
scale = float(dtype_limits(image, True)[1] - dtype_limits(image, True)[0])
if inv == True:
out = (2 ** (image / scale) - 1) * scale * gain
return dtype(out)
if inv == True:
out = (2 ** (image / scale) - 1) * scale * gain
return dtype(out)
out = np.log2(1 + image / scale) * scale * gain
return dtype(out)
def rescale_intensity_sigmoid(image, cutoff=0.5, gain=10, inv=False):
def adjust_sigmoid(image, cutoff=0.5, gain=10, inv=False):
"""Performs Sigmoid Correction on the input image.
Also known as Contrast Adjustment.
@@ -345,13 +344,13 @@ def rescale_intensity_sigmoid(image, cutoff=0.5, gain=10, inv=False):
.. [1] http://bme.med.upatras.gr/improc/matalb_code_toc.htm#12. Adjust Contrast :
"""
_assert_non_negative(image)
dtype = image.dtype.type
scale = float(dtype_limits(image, True)[1] - dtype_limits(image, True)[0])
if _assert_not_negative(image):
scale = float(dtype_limits(image, True)[1] - dtype_limits(image, True)[0])
if inv == True:
out = (1 - 1 / (1 + np.exp(gain * (cutoff - image/scale)))) * scale
return dtype(out)
out = (1 / (1 + np.exp(gain * (cutoff - image/scale)))) * scale
if inv == True:
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)
+20 -20
View File
@@ -181,22 +181,22 @@ if __name__ == '__main__':
# Test Gamma Correction
# =====================
def test_rescale_intensity_gamma_one():
def test_adjust_gamma_one():
"""Same image should be returned for gamma equal to one"""
image = np.random.uniform(0, 255, (8, 8))
result = exposure.rescale_intensity_gamma(image, 1)
result = exposure.adjust_gamma(image, 1)
assert_array_equal(result, image)
def test_rescale_intensity_gamma_zero():
def test_adjust_gamma_zero():
"""White image should be returned for gamma equal to zero"""
image = np.random.uniform(0, 255, (8, 8))
result = exposure.rescale_intensity_gamma(image, 0)
result = exposure.adjust_gamma(image, 0)
dtype = image.dtype.type
assert_array_equal(result, dtype_range[dtype][1])
def test_rescale_intensity_gamma_less_one():
def test_adjust_gamma_less_one():
"""Verifying the output with expected results for gamma
correction with gamma equal to half"""
image = np.arange(0, 255, 4, np.uint8).reshape(8,8)
@@ -209,11 +209,11 @@ def test_rescale_intensity_gamma_less_one():
[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)
result = exposure.adjust_gamma(image, 0.5)
assert_array_equal(result, expected)
def test_rescale_intensity_gamma_greater_one():
def test_adjust_gamma_greater_one():
"""Verifying the output with expected results for gamma
correction with gamma equal to two"""
image = np.arange(0, 255, 4, np.uint8).reshape(8,8)
@@ -226,14 +226,14 @@ def test_rescale_intensity_gamma_greater_one():
[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)
result = exposure.adjust_gamma(image, 2)
assert_array_equal(result, expected)
# Test Logarithmic Correction
# ===========================
def test_rescale_intensity_log():
def test_adjust_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)
@@ -246,11 +246,11 @@ def test_rescale_intensity_log():
[206, 209, 213, 216, 219, 222, 225, 228],
[231, 234, 238, 241, 244, 246, 249, 252]], dtype=np.uint8)
result = exposure.rescale_intensity_log(image, 1)
result = exposure.adjust_log(image, 1)
assert_array_equal(result, expected)
def test_rescale_intensity_inv_log():
def test_adjust_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)
@@ -263,14 +263,14 @@ def test_rescale_intensity_inv_log():
[174, 179, 184, 188, 193, 198, 203, 208],
[213, 218, 224, 229, 234, 239, 245, 250]], dtype=np.uint8)
result = exposure.rescale_intensity_log(image, 1, True)
result = exposure.adjust_log(image, 1, True)
assert_array_equal(result, expected)
# Test Sigmoid Correction
# =======================
def test_rescale_intensity_sigmoid_cutoff_one():
def test_adjust_sigmoid_cutoff_one():
"""Verifying the output with expected results for sigmoid correction
with cutoff equal to one and gain of 5"""
image = np.arange(0, 255, 4, np.uint8).reshape(8,8)
@@ -283,11 +283,11 @@ def test_rescale_intensity_sigmoid_cutoff_one():
[ 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)
result = exposure.adjust_sigmoid(image, 1, 5)
assert_array_equal(result, expected)
def test_rescale_intensity_sigmoid_cutoff_zero():
def test_adjust_sigmoid_cutoff_zero():
"""Verifying the output with expected results for sigmoid correction
with cutoff equal to zero and gain of 10"""
image = np.arange(0, 255, 4, np.uint8).reshape(8,8)
@@ -300,11 +300,11 @@ def test_rescale_intensity_sigmoid_cutoff_zero():
[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)
result = exposure.adjust_sigmoid(image, 0, 10)
assert_array_equal(result, expected)
def test_rescale_intensity_sigmoid_cutoff_half():
def test_adjust_sigmoid_cutoff_half():
"""Verifying the output with expected results for sigmoid correction
with cutoff equal to half and gain of 10"""
image = np.arange(0, 255, 4, np.uint8).reshape(8,8)
@@ -317,11 +317,11 @@ def test_rescale_intensity_sigmoid_cutoff_half():
[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)
result = exposure.adjust_sigmoid(image, 0.5, 10)
assert_array_equal(result, expected)
def test_rescale_intensity_inv_sigmoid_cutoff_half():
def test_adjust_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)
@@ -334,5 +334,5 @@ def test_rescale_intensity_inv_sigmoid_cutoff_half():
[ 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)
result = exposure.adjust_sigmoid(image, 0.5, 10, True)
assert_array_equal(result, expected)