Merge pull request #1660 from jwiggins/issue-1586

Raise an error for negative sigma values in guassian_filter.
This commit is contained in:
Emmanuelle Gouillart
2015-08-29 15:59:12 +02:00
2 changed files with 12 additions and 0 deletions
+2
View File
@@ -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):
+10
View File
@@ -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.