Supports skimage_range. Displays deprecated warning when used. Two test cases to test this functionality.

This commit is contained in:
Pradyumna Narayana
2016-03-04 08:32:57 -07:00
parent 428cc3daeb
commit f069aada3c
3 changed files with 37 additions and 5 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ Build Requirements
------------------
* `Python >= 2.6 <http://python.org>`__
* `Numpy >= 1.7.2 <http://numpy.scipy.org/>`__
* `Cython >= 0.21 <http://www.cython.org/>`__
* `Cython >= 0.23 <http://www.cython.org/>`__
* `Six >=1.4 <https://pypi.python.org/pypi/six>`__
* `SciPy >=0.9 <http://scipy.org>`__
+11 -3
View File
@@ -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)
+25 -1
View File
@@ -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))