From a63e3f454633bea824c0c15afc019ee3620c944f Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Wed, 26 Oct 2011 16:22:20 -0400 Subject: [PATCH] Require median filter radius >= 2 The octagon structuring element used by _ctmf.pyx does not scale correctly for smaller radii. --- skimage/filter/ctmf.py | 3 +++ skimage/filter/tests/test_ctmf.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/skimage/filter/ctmf.py b/skimage/filter/ctmf.py index 1f294ee4..38fe32eb 100644 --- a/skimage/filter/ctmf.py +++ b/skimage/filter/ctmf.py @@ -47,6 +47,9 @@ def median_filter(image, mask=None, radius=2, percent=50): if image.ndim != 2: raise TypeError("The input 'image' must be a two dimensional array.") + if radius < 2: + raise ValueError("The input 'radius' must be >= 2.") + if mask is None: mask = np.ones(image.shape, dtype=np.bool) mask = np.ascontiguousarray(mask, dtype=np.bool) diff --git a/skimage/filter/tests/test_ctmf.py b/skimage/filter/tests/test_ctmf.py index a3c23fe4..dfe35f46 100644 --- a/skimage/filter/tests/test_ctmf.py +++ b/skimage/filter/tests/test_ctmf.py @@ -1,4 +1,5 @@ import numpy as np +from nose.tools import raises from skimage.filter import median_filter @@ -110,5 +111,11 @@ def test_default_values(): np.testing.assert_array_equal(result1, result2) +@raises(ValueError) +def test_insufficient_size(): + img = (np.random.random((20, 20)) * 255).astype(np.uint8) + median_filter(img, radius=1) + + if __name__ == "__main__": np.testing.run_module_suite()