From b1e0597ee15dc35ad9a75cabd8ef4b1ee699945d Mon Sep 17 00:00:00 2001 From: Himanshu Mishra Date: Fri, 22 Jan 2016 13:43:47 +0530 Subject: [PATCH] Raise warning for 3D images in denoise_bilateral --- skimage/restoration/_denoise.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/skimage/restoration/_denoise.py b/skimage/restoration/_denoise.py index 62985cc7..754fcf97 100644 --- a/skimage/restoration/_denoise.py +++ b/skimage/restoration/_denoise.py @@ -3,10 +3,11 @@ import numpy as np 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, - bins=10000, mode='constant', cval=0): + bins=10000, mode='constant', cval=0, multichannel=False): """Denoise image using bilateral filter. This is an edge-preserving and noise reducing denoising filter. It averages @@ -45,6 +46,9 @@ def denoise_bilateral(image, win_size=5, sigma_range=None, sigma_spatial=1, cval : string Used in conjunction with mode 'constant', the value outside the image boundaries. + multichannel : bool, default False + Whether the last axis of the image is to be interpreted as multiple + channels or another spatial dimension. Returns ------- @@ -64,6 +68,18 @@ def denoise_bilateral(image, win_size=5, sigma_range=None, sigma_spatial=1, >>> noisy = np.clip(noisy, 0, 1) >>> denoised = denoise_bilateral(noisy, sigma_range=0.05, sigma_spatial=15) """ + if multichannel: + if image.shape[2] not in (3, 4): + msg = "Input image must be grayscale, RGB, or RGBA; but has " \ + "a shape {0}." + warnings.warn(msg.format(image.shape)) + else: + if image.ndim > 2: + msg = "Input image must be grayscale, RGB, or RGBA; but has " \ + "a shape {0}." + raise TypeError(msg.format(image.shape)) + + mode = _mode_deprecations(mode) return _denoise_bilateral(image, win_size, sigma_range, sigma_spatial, bins, mode, cval)