Update equalize_adapthist to use new view_as_windows

Update equalize_adapthist to use new view_as_windows

Try rbase again

Update equalize_adapthist to use new view_as_windows

Fix relative imports

Style fixes

Add a deprecation warning and add to api_changes.txt

Update TODO and switch to 0.13 deprecation

Preserve the current API as much as possible and defer to 0.14

Move the new kwarg to the very end

Clarify deprecation warning

Update to use row/col in clahe

Update docstring

Use optimal_step to set up view_as_windows

Update equalize_adapthist to use new view_as_windows

Try rbase again

Update equalize_adapthist to use new view_as_windows

Fix relative imports
This commit is contained in:
Steven Silvester
2015-06-15 21:35:30 -05:00
parent 1b30c68d28
commit 998be36c2d
2 changed files with 26 additions and 6 deletions
+23
View File
@@ -20,15 +20,23 @@ from .. import img_as_float, img_as_uint
from ..color.adapt_rgb import adapt_rgb, hsv_value
from ..exposure import rescale_intensity
from ..util import view_as_windows
<<<<<<< HEAD
from .._shared.utils import skimage_deprecation, warnings
=======
>>>>>>> 3bcbbc0... Update equalize_adapthist to use new view_as_windows
NR_OF_GREY = 2 ** 14 # number of grayscale levels to use in CLAHE algorithm
@adapt_rgb(hsv_value)
<<<<<<< HEAD
def equalize_adapthist(image, ntiles_x=8, ntiles_y=8, clip_limit=0.01,
nbins=256, kernel_size=None):
=======
def equalize_adapthist(image, kernel_size=64, ntiles_x=None, ntiles_y=None,
clip_limit=0.01, nbins=256):
>>>>>>> 3bcbbc0... Update equalize_adapthist to use new view_as_windows
"""Contrast Limited Adaptive Histogram Equalization (CLAHE).
An algorithm for local contrast enhancement, that uses histograms computed
@@ -42,11 +50,19 @@ def equalize_adapthist(image, ntiles_x=8, ntiles_y=8, clip_limit=0.01,
kernel_size: integer or 2-tuple
Defines the shape of contextual regions used in the algorithm.
If an integer is given, the shape will be a square of
<<<<<<< HEAD
sidelength given by this value.
ntiles_x : int, optional (deprecated in favor of ``kernel_size``)
Number of tile regions in the X direction (horizontal).
ntiles_y : int, optional (deprecated if favor of ``kernel_size``)
Number of tile regions in the Y direction (vertical).
=======
sidelength given by its value.
ntiles_x : int, optional
Number of tile regions in the X direction.
ntiles_y : int, optional
Number of tile regions in the Y direction.
>>>>>>> 3bcbbc0... Update equalize_adapthist to use new view_as_windows
clip_limit : float: optional
Clipping limit, normalized between 0 and 1 (higher values give more
contrast).
@@ -77,6 +93,7 @@ def equalize_adapthist(image, ntiles_x=8, ntiles_y=8, clip_limit=0.01,
"""
image = img_as_uint(image)
image = rescale_intensity(image, out_range=(0, NR_OF_GREY - 1))
<<<<<<< HEAD
if kernel_size is None:
warnings.warn('`ntiles_*` have been deprecated in favor of '
'`kernel_size`. The `ntiles_*` keyword arguments '
@@ -85,6 +102,12 @@ def equalize_adapthist(image, ntiles_x=8, ntiles_y=8, clip_limit=0.01,
ntiles_y = ntiles_y or 8
kernel_size = (np.round(image.shape[0] / ntiles_y),
np.round(image.shape[1] / ntiles_x))
=======
if ntiles_x or ntiles_y:
ntiles_x = ntiles_x or 8
ntiles_y = ntiles_y or 8
kernel_size = (image.shape[0] / ntiles_y, image.shape[1] / ntiles_x)
>>>>>>> 3bcbbc0... Update equalize_adapthist to use new view_as_windows
if isinstance(kernel_size, numbers.Number):
kernel_size = (kernel_size, kernel_size)
+3 -6
View File
@@ -211,17 +211,14 @@ def test_adapthist_grayscale():
img = skimage.img_as_float(data.astronaut())
img = rgb2gray(img)
img = np.dstack((img, img, img))
with expected_warnings(['precision loss|non-contiguous input', 'deprecated']):
with expected_warnings(['precision loss|non-contiguous input',
'deprecated']):
adapted_old = exposure.equalize_adapthist(img, 10, 9, clip_limit=0.01,
nbins=128)
adapted = exposure.equalize_adapthist(img, kernel_size=(57, 51), clip_limit=0.01,
nbins=128)
np.testing.assert_allclose(adapted, adapted_old)
adapted = exposure.equalize_adapthist(img, kernel_size=(57, 51), clip_limit=0.01, nbins=128)
assert_almost_equal = np.testing.assert_almost_equal
assert img.shape == adapted.shape
assert_almost_equal(peak_snr(img, adapted), 90.669, 3)
assert_almost_equal(norm_brightness_err(img, adapted), 0.084, 3)
return data, adapted