sigma_range is renamed to sigma_color and win_size scales with sigma_spatial

This commit is contained in:
Pradyumna Narayana
2016-03-03 12:00:15 -07:00
parent 14852f4578
commit 9f3fc737ba
2 changed files with 11 additions and 8 deletions
+7 -4
View File
@@ -1,12 +1,13 @@
# coding: utf-8
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
import warnings
def denoise_bilateral(image, win_size=5, sigma_range=None, sigma_spatial=1,
def denoise_bilateral(image, win_size=None, sigma_color=None, sigma_spatial=1,
bins=10000, mode='constant', cval=0, multichannel=True):
"""Denoise image using bilateral filter.
@@ -19,7 +20,7 @@ def denoise_bilateral(image, win_size=5, sigma_range=None, sigma_spatial=1,
Radiometric similarity is measured by the gaussian function of the euclidian
distance between two color values and a certain standard deviation
(`sigma_range`).
(`sigma_color`).
Parameters
----------
@@ -66,7 +67,7 @@ def denoise_bilateral(image, win_size=5, sigma_range=None, sigma_spatial=1,
>>> astro = astro[220:300, 220:320]
>>> noisy = astro + 0.6 * astro.std() * np.random.random(astro.shape)
>>> noisy = np.clip(noisy, 0, 1)
>>> denoised = denoise_bilateral(noisy, sigma_range=0.05, sigma_spatial=15)
>>> denoised = denoise_bilateral(noisy, sigma_color=0.05, sigma_spatial=15)
"""
if multichannel:
if image.ndim != 3:
@@ -99,9 +100,11 @@ def denoise_bilateral(image, win_size=5, sigma_range=None, sigma_spatial=1,
"``multichannel=True`` for 2-D RGB "
"images.".format(image.shape))
if win_size is None:
win_size = max(5, 2*ceil(3*sigma_spatial)+1)
mode = _mode_deprecations(mode)
return _denoise_bilateral(image, win_size, sigma_range, sigma_spatial,
return _denoise_bilateral(image, win_size, sigma_color, sigma_spatial,
bins, mode, cval)
+4 -4
View File
@@ -159,9 +159,9 @@ def test_denoise_bilateral_2d():
img += 0.5 * img.std() * np.random.rand(*img.shape)
img = np.clip(img, 0, 1)
out1 = restoration.denoise_bilateral(img, sigma_range=0.1,
out1 = restoration.denoise_bilateral(img, sigma_color=0.1,
sigma_spatial=20, multichannel=False)
out2 = restoration.denoise_bilateral(img, sigma_range=0.2,
out2 = restoration.denoise_bilateral(img, sigma_color=0.2,
sigma_spatial=30, multichannel=False)
# make sure noise is reduced in the checkerboard cells
@@ -175,8 +175,8 @@ def test_denoise_bilateral_color():
img += 0.5 * img.std() * np.random.rand(*img.shape)
img = np.clip(img, 0, 1)
out1 = restoration.denoise_bilateral(img, sigma_range=0.1, sigma_spatial=20)
out2 = restoration.denoise_bilateral(img, sigma_range=0.2, sigma_spatial=30)
out1 = restoration.denoise_bilateral(img, sigma_color=0.1, sigma_spatial=20)
out2 = restoration.denoise_bilateral(img, sigma_color=0.2, sigma_spatial=30)
# make sure noise is reduced in the checkerboard cells
assert img[30:45, 5:15].std() > out1[30:45, 5:15].std()