From f069aada3c06dddcfdfbdd06986167007c8c2842 Mon Sep 17 00:00:00 2001 From: Pradyumna Narayana Date: Fri, 4 Mar 2016 08:32:57 -0700 Subject: [PATCH] Supports skimage_range. Displays deprecated warning when used. Two test cases to test this functionality. --- DEPENDS.txt | 2 +- skimage/restoration/_denoise.py | 14 +++++++++--- skimage/restoration/tests/test_denoise.py | 26 ++++++++++++++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/DEPENDS.txt b/DEPENDS.txt index fc6d6679..edfe2dfa 100644 --- a/DEPENDS.txt +++ b/DEPENDS.txt @@ -2,7 +2,7 @@ Build Requirements ------------------ * `Python >= 2.6 `__ * `Numpy >= 1.7.2 `__ -* `Cython >= 0.21 `__ +* `Cython >= 0.23 `__ * `Six >=1.4 `__ * `SciPy >=0.9 `__ diff --git a/skimage/restoration/_denoise.py b/skimage/restoration/_denoise.py index 2151bbef..0519f39c 100644 --- a/skimage/restoration/_denoise.py +++ b/skimage/restoration/_denoise.py @@ -3,12 +3,12 @@ import numpy as np from math import ceil from .. import img_as_float from ..restoration._denoise_cy import _denoise_bilateral, _denoise_tv_bregman -from .._shared.utils import _mode_deprecations +from .._shared.utils import _mode_deprecations, skimage_deprecation, warn import warnings def denoise_bilateral(image, win_size=None, sigma_color=None, sigma_spatial=1, - bins=10000, mode='constant', cval=0, multichannel=True): + bins=10000, mode='constant', cval=0, multichannel=True, sigma_range=None): """Denoise image using bilateral filter. This is an edge-preserving and noise reducing denoising filter. It averages @@ -29,7 +29,7 @@ def denoise_bilateral(image, win_size=None, sigma_color=None, sigma_spatial=1, win_size : int Window size for filtering. If win_size is not specified, it is calculated as max(5, 2*ceil(3*sigma_spatial)+1) - sigma_range : float + sigma_color : float Standard deviation for grayvalue/color distance (radiometric similarity). A larger value results in averaging of pixels with larger radiometric differences. Note, that the image will be converted using @@ -101,6 +101,14 @@ def denoise_bilateral(image, win_size=None, sigma_color=None, sigma_spatial=1, "``multichannel=True`` for 2-D RGB " "images.".format(image.shape)) + if sigma_range is not None: + warn('`sigma_range` have been deprecated in favor of ' + '`sigma_color`. The `sigma_range` keyword argument ' + 'will be removed in v0.14', skimage_deprecation) + + #If sigma_range is provided, assign it to sigma_color + sigma_color = sigma_range + if win_size is None: win_size = max(5, 2*int(ceil(3*sigma_spatial))+1) diff --git a/skimage/restoration/tests/test_denoise.py b/skimage/restoration/tests/test_denoise.py index da963749..7bf9c7bf 100644 --- a/skimage/restoration/tests/test_denoise.py +++ b/skimage/restoration/tests/test_denoise.py @@ -4,7 +4,6 @@ from numpy.testing import run_module_suite, assert_raises, assert_equal from skimage import restoration, data, color, img_as_float, measure from skimage._shared._warnings import expected_warnings - np.random.seed(1234) @@ -212,6 +211,31 @@ def test_denoise_bilateral_nan(): out = restoration.denoise_bilateral(img, multichannel=False) assert_equal(img, out) +def test_denoise_sigma_range(): + img = checkerboard_gray.copy() + # add some random noise + img += 0.5 * img.std() * np.random.rand(*img.shape) + img = np.clip(img, 0, 1) + out1 = restoration.denoise_bilateral(img, sigma_color=0.1, + sigma_spatial=20, multichannel=False) + with expected_warnings('`sigma_range` have been deprecated in favor of `sigma_color`. ' + 'The `sigma_range` keyword argument will be removed in v0.14'): + out2 = restoration.denoise_bilateral(img, sigma_range=0.1, + sigma_spatial=20, multichannel=False) + assert_equal(out1, out2) + +def test_denoise_sigma_range_and_sigma_color(): + img = checkerboard_gray.copy() + # add some random noise + img += 0.5 * img.std() * np.random.rand(*img.shape) + img = np.clip(img, 0, 1) + out1 = restoration.denoise_bilateral(img, sigma_color=0.1, + sigma_spatial=20, multichannel=False) + with expected_warnings('`sigma_range` have been deprecated in favor of `sigma_color`. ' + 'The `sigma_range` keyword argument will be removed in v0.14'): + out2 = restoration.denoise_bilateral(img, sigma_color=0.2, sigma_range=0.1, + sigma_spatial=20, multichannel=False) + assert_equal(out1, out2) def test_nl_means_denoising_2d(): img = np.zeros((40, 40))