diff --git a/skimage/filters/_gaussian.py b/skimage/filters/_gaussian.py index 6bc12574..85b572ca 100644 --- a/skimage/filters/_gaussian.py +++ b/skimage/filters/_gaussian.py @@ -93,6 +93,8 @@ def gaussian_filter(image, sigma, output=None, mode='nearest', cval=0, "3D image with last dimension of length 3.") warnings.warn(RuntimeWarning(msg)) multichannel = True + if np.any(np.asarray(sigma) < 0.0): + raise ValueError("Sigma values less than zero are not valid") if multichannel: # do not filter across channels if not isinstance(sigma, coll.Iterable): diff --git a/skimage/filters/tests/test_gaussian.py b/skimage/filters/tests/test_gaussian.py index c88ee1f8..14c95d0e 100644 --- a/skimage/filters/tests/test_gaussian.py +++ b/skimage/filters/tests/test_gaussian.py @@ -1,8 +1,18 @@ import numpy as np +from numpy.testing import assert_raises from skimage.filters._gaussian import gaussian_filter from skimage._shared._warnings import expected_warnings +def test_negative_sigma(): + a = np.zeros((3, 3)) + a[1, 1] = 1. + assert_raises(ValueError, gaussian_filter, a, sigma=-1.0) + assert_raises(ValueError, gaussian_filter, a, sigma=[-1.0, 1.0]) + assert_raises(ValueError, gaussian_filter, a, + sigma=np.asarray([-1.0, 1.0])) + + def test_null_sigma(): a = np.zeros((3, 3)) a[1, 1] = 1.