From 24d771d3335a2e54261bdbdbffcb301648c09bac Mon Sep 17 00:00:00 2001 From: Andreas Mueller Date: Mon, 26 Sep 2011 17:21:58 +0200 Subject: [PATCH] check if input for canny is 2d array, test for error raise. --- scikits/image/filter/canny.py | 4 ++++ scikits/image/filter/tests/test_canny.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/scikits/image/filter/canny.py b/scikits/image/filter/canny.py index 341d5b77..dd3b5608 100644 --- a/scikits/image/filter/canny.py +++ b/scikits/image/filter/canny.py @@ -111,6 +111,10 @@ def canny(image, sigma, low_threshold, high_threshold, mask=None): # mask by one and then mask the output. We also mask out the border points # because who knows what lies beyond the edge of the image? # + + if image.ndim!=2: + raise TypeError("The input 'image' must be a two dimensional array.") + if mask is None: mask = np.ones(image.shape, dtype=bool) fsmooth = lambda x: gaussian_filter(x, sigma, mode='constant') diff --git a/scikits/image/filter/tests/test_canny.py b/scikits/image/filter/tests/test_canny.py index f7002773..ddadc790 100644 --- a/scikits/image/filter/tests/test_canny.py +++ b/scikits/image/filter/tests/test_canny.py @@ -56,3 +56,6 @@ class TestCanny(unittest.TestCase): point_count = np.sum(result) self.assertTrue(point_count > 1200) self.assertTrue(point_count < 1600) + + def test_image_shape(self): + self.assertRaises(TypeError,F.canny,np.zeros((20, 20, 20)), 4, 0, 0)