From f22a014ffaa07856e33a5bda678d87673fefb3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Fri, 12 Oct 2012 19:10:46 +0200 Subject: [PATCH 1/7] Add scharr edge filter --- skimage/filter/__init__.py | 3 +- skimage/filter/edges.py | 114 +++++++++++++++++++++++++-- skimage/filter/tests/test_edges.py | 120 +++++++++++++++++++++++++++++ 3 files changed, 228 insertions(+), 9 deletions(-) diff --git a/skimage/filter/__init__.py b/skimage/filter/__init__.py index bdbbb531..f76556df 100644 --- a/skimage/filter/__init__.py +++ b/skimage/filter/__init__.py @@ -1,7 +1,8 @@ from .lpi_filter import * from .ctmf import median_filter from ._canny import canny -from .edges import sobel, hsobel, vsobel, hprewitt, vprewitt, prewitt +from .edges import (sobel, hsobel, vsobel, scharr, hscharr, vscharr, prewitt, + hprewitt, vprewitt) from ._tv_denoise import tv_denoise from ._rank_order import rank_order from .thresholding import threshold_otsu, threshold_adaptive diff --git a/skimage/filter/edges.py b/skimage/filter/edges.py index 134aa796..98e4f600 100644 --- a/skimage/filter/edges.py +++ b/skimage/filter/edges.py @@ -1,6 +1,7 @@ -"""edges.py - Sobel edge filter +"""edges.py - Edge filters -Originally part of CellProfiler, code licensed under both GPL and BSD licenses. +Sobel and Prewitt filters originally part of CellProfiler, code licensed under +both GPL and BSD licenses. Website: http://www.cellprofiler.org Copyright (c) 2003-2009 Massachusetts Institute of Technology Copyright (c) 2009-2011 Broad Institute @@ -48,7 +49,7 @@ def sobel(image, mask=None): Returns ------- output : ndarray - The Sobel edge map. + The Sobel edge map. Notes ----- @@ -77,7 +78,7 @@ def hsobel(image, mask=None): Returns ------- output : ndarray - The Sobel edge map. + The Sobel edge map. Notes ----- @@ -112,7 +113,7 @@ def vsobel(image, mask=None): Returns ------- output : ndarray - The Sobel edge map. + The Sobel edge map. Notes ----- @@ -132,6 +133,103 @@ def vsobel(image, mask=None): return _mask_filter_result(result, mask) +def scharr(image, mask=None): + """Calculate the absolute magnitude Scharr to find edges. + + Parameters + ---------- + image : array_like, dtype=float + Image to process. + mask : array_like, dtype=bool, optional + An optional mask to limit the application to a certain area. + Note that pixels surrounding masked regions are also masked to + prevent masked regions from affecting the result. + + Returns + ------- + output : ndarray + The Scharr edge map. + + Notes + ----- + Take the square root of the sum of the squares of the horizontal and + vertical Scharrs to get a magnitude that's somewhat insensitive to + direction. + + """ + return np.sqrt(hscharr(image, mask)**2 + vscharr(image, mask)**2) + + +def hscharr(image, mask=None): + """Find the horizontal edges of an image using the Scharr transform. + + Parameters + ---------- + image : array_like, dtype=float + Image to process. + mask : array_like, dtype=bool, optional + An optional mask to limit the application to a certain area. + Note that pixels surrounding masked regions are also masked to + prevent masked regions from affecting the result. + + Returns + ------- + output : ndarray + The Scharr edge map. + + Notes + ----- + We use the following kernel and return the absolute value of the + result at each point:: + + 3 10 3 + 0 0 0 + -3 -10 -3 + + """ + image = img_as_float(image) + result = np.abs(convolve(image, + np.array([[ 3, 10, 3], + [ 0, 0, 0], + [-3, -10, -3]]).astype(float) / 16.0)) + return _mask_filter_result(result, mask) + + +def vscharr(image, mask=None): + """Find the vertical edges of an image using the Scharr transform. + + Parameters + ---------- + image : array_like, dtype=float + Image to process + mask : array_like, dtype=bool, optional + An optional mask to limit the application to a certain area + Note that pixels surrounding masked regions are also masked to + prevent masked regions from affecting the result. + + Returns + ------- + output : ndarray + The Scharr edge map. + + Notes + ----- + We use the following kernel and return the absolute value of the + result at each point:: + + 3 0 -3 + 10 0 -10 + 3 0 -3 + + """ + image = img_as_float(image) + result = np.abs(convolve(image, + np.array([[ 3, 0, -3], + [10, 0, -10], + [ 3, 0, -3]]).astype(float) / 16.0)) + return _mask_filter_result(result, mask) + + def prewitt(image, mask=None): """Find the edge magnitude using the Prewitt transform. @@ -147,7 +245,7 @@ def prewitt(image, mask=None): Returns ------- output : ndarray - The Prewitt edge map. + The Prewitt edge map. Notes ----- @@ -172,7 +270,7 @@ def hprewitt(image, mask=None): Returns ------- output : ndarray - The Prewitt edge map. + The Prewitt edge map. Notes ----- @@ -207,7 +305,7 @@ def vprewitt(image, mask=None): Returns ------- output : ndarray - The Prewitt edge map. + The Prewitt edge map. Notes ----- diff --git a/skimage/filter/tests/test_edges.py b/skimage/filter/tests/test_edges.py index a5d52aa5..1edf8914 100644 --- a/skimage/filter/tests/test_edges.py +++ b/skimage/filter/tests/test_edges.py @@ -9,6 +9,7 @@ def test_sobel_zeros(): result = F.sobel(np.zeros((10, 10)), np.ones((10, 10), bool)) assert (np.all(result == 0)) + def test_sobel_mask(): """Sobel on a masked array should be zero""" np.random.seed(0) @@ -16,6 +17,7 @@ def test_sobel_mask(): np.zeros((10, 10), bool)) assert (np.all(result == 0)) + def test_sobel_horizontal(): """Sobel on an edge should be a horizontal line""" i, j = np.mgrid[-5:6, -5:6] @@ -26,6 +28,7 @@ def test_sobel_horizontal(): assert (np.all(result[i == 0] == 1)) assert (np.all(result[np.abs(i) > 1] == 0)) + def test_sobel_vertical(): """Sobel on a vertical edge should be a vertical line""" i, j = np.mgrid[-5:6, -5:6] @@ -41,6 +44,7 @@ def test_hsobel_zeros(): result = F.hsobel(np.zeros((10, 10)), np.ones((10, 10), bool)) assert (np.all(result == 0)) + def test_hsobel_mask(): """Horizontal Sobel on a masked array should be zero""" np.random.seed(0) @@ -48,6 +52,7 @@ def test_hsobel_mask(): np.zeros((10, 10), bool)) assert (np.all(result == 0)) + def test_hsobel_horizontal(): """Horizontal Sobel on an edge should be a horizontal line""" i, j = np.mgrid[-5:6, -5:6] @@ -58,6 +63,7 @@ def test_hsobel_horizontal(): assert (np.all(result[i == 0] == 1)) assert (np.all(result[np.abs(i) > 1] == 0)) + def test_hsobel_vertical(): """Horizontal Sobel on a vertical edge should be zero""" i, j = np.mgrid[-5:6, -5:6] @@ -71,6 +77,7 @@ def test_vsobel_zeros(): result = F.vsobel(np.zeros((10, 10)), np.ones((10, 10), bool)) assert (np.all(result == 0)) + def test_vsobel_mask(): """Vertical Sobel on a masked array should be zero""" np.random.seed(0) @@ -78,6 +85,7 @@ def test_vsobel_mask(): np.zeros((10, 10), bool)) assert (np.all(result == 0)) + def test_vsobel_vertical(): """Vertical Sobel on an edge should be a vertical line""" i, j = np.mgrid[-5:6, -5:6] @@ -88,6 +96,7 @@ def test_vsobel_vertical(): assert (np.all(result[j == 0] == 1)) assert (np.all(result[np.abs(j) > 1] == 0)) + def test_vsobel_horizontal(): """vertical Sobel on a horizontal edge should be zero""" i, j = np.mgrid[-5:6, -5:6] @@ -97,11 +106,114 @@ def test_vsobel_horizontal(): assert (np.all(np.abs(result) < eps)) +def test_scharr_zeros(): + """Sobel on an array of all zeros""" + result = F.scharr(np.zeros((10, 10)), np.ones((10, 10), bool)) + assert (np.all(result == 0)) + + +def test_scharr_mask(): + """Sobel on a masked array should be zero""" + np.random.seed(0) + result = F.scharr(np.random.uniform(size=(10, 10)), + np.zeros((10, 10), bool)) + assert (np.all(result == 0)) + + +def test_scharr_horizontal(): + """Sobel on an edge should be a horizontal line""" + i, j = np.mgrid[-5:6, -5:6] + image = (i >= 0).astype(float) + result = F.scharr(image) + # Fudge the eroded points + i[np.abs(j) == 5] = 10000 + assert (np.all(result[i == 0] == 1)) + assert (np.all(result[np.abs(i) > 1] == 0)) + + +def test_scharr_vertical(): + """Sobel on a vertical edge should be a vertical line""" + i, j = np.mgrid[-5:6, -5:6] + image = (j >= 0).astype(float) + result = F.scharr(image) + j[np.abs(i) == 5] = 10000 + assert (np.all(result[j == 0] == 1)) + assert (np.all(result[np.abs(j) > 1] == 0)) + + +def test_hscharr_zeros(): + """Horizontal sobel on an array of all zeros""" + result = F.hscharr(np.zeros((10, 10)), np.ones((10, 10), bool)) + assert (np.all(result == 0)) + + +def test_hscharr_mask(): + """Horizontal Sobel on a masked array should be zero""" + np.random.seed(0) + result = F.hscharr(np.random.uniform(size=(10, 10)), + np.zeros((10, 10), bool)) + assert (np.all(result == 0)) + + +def test_hscharr_horizontal(): + """Horizontal Sobel on an edge should be a horizontal line""" + i, j = np.mgrid[-5:6, -5:6] + image = (i >= 0).astype(float) + result = F.hscharr(image) + # Fudge the eroded points + i[np.abs(j) == 5] = 10000 + assert (np.all(result[i == 0] == 1)) + assert (np.all(result[np.abs(i) > 1] == 0)) + + +def test_hscharr_vertical(): + """Horizontal Sobel on a vertical edge should be zero""" + i, j = np.mgrid[-5:6, -5:6] + image = (j >= 0).astype(float) + result = F.hscharr(image) + assert (np.all(result == 0)) + + +def test_vscharr_zeros(): + """Vertical sobel on an array of all zeros""" + result = F.vscharr(np.zeros((10, 10)), np.ones((10, 10), bool)) + assert (np.all(result == 0)) + + +def test_vscharr_mask(): + """Vertical Sobel on a masked array should be zero""" + np.random.seed(0) + result = F.vscharr(np.random.uniform(size=(10, 10)), + np.zeros((10, 10), bool)) + assert (np.all(result == 0)) + + +def test_vscharr_vertical(): + """Vertical Sobel on an edge should be a vertical line""" + i, j = np.mgrid[-5:6, -5:6] + image = (j >= 0).astype(float) + result = F.vscharr(image) + # Fudge the eroded points + j[np.abs(i) == 5] = 10000 + assert (np.all(result[j == 0] == 1)) + assert (np.all(result[np.abs(j) > 1] == 0)) + + +def test_vscharr_horizontal(): + """vertical Sobel on a horizontal edge should be zero""" + i, j = np.mgrid[-5:6, -5:6] + image = (i >= 0).astype(float) + result = F.vscharr(image) + eps = .000001 + assert (np.all(np.abs(result) < eps)) + + def test_prewitt_zeros(): """Prewitt on an array of all zeros""" result = F.prewitt(np.zeros((10, 10)), np.ones((10, 10), bool)) assert (np.all(result == 0)) + def test_prewitt_mask(): """Prewitt on a masked array should be zero""" np.random.seed(0) @@ -110,6 +222,7 @@ def test_prewitt_mask(): eps = .000001 assert (np.all(np.abs(result) < eps)) + def test_prewitt_horizontal(): """Prewitt on an edge should be a horizontal line""" i, j = np.mgrid[-5:6, -5:6] @@ -121,6 +234,7 @@ def test_prewitt_horizontal(): assert (np.all(result[i == 0] == 1)) assert (np.all(np.abs(result[np.abs(i) > 1]) < eps)) + def test_prewitt_vertical(): """Prewitt on a vertical edge should be a vertical line""" i, j = np.mgrid[-5:6, -5:6] @@ -137,6 +251,7 @@ def test_hprewitt_zeros(): result = F.hprewitt(np.zeros((10, 10)), np.ones((10, 10), bool)) assert (np.all(result == 0)) + def test_hprewitt_mask(): """Horizontal prewitt on a masked array should be zero""" np.random.seed(0) @@ -145,6 +260,7 @@ def test_hprewitt_mask(): eps = .000001 assert (np.all(np.abs(result) < eps)) + def test_hprewitt_horizontal(): """Horizontal prewitt on an edge should be a horizontal line""" i, j = np.mgrid[-5:6, -5:6] @@ -156,6 +272,7 @@ def test_hprewitt_horizontal(): assert (np.all(result[i == 0] == 1)) assert (np.all(np.abs(result[np.abs(i) > 1]) < eps)) + def test_hprewitt_vertical(): """Horizontal prewitt on a vertical edge should be zero""" i, j = np.mgrid[-5:6, -5:6] @@ -170,6 +287,7 @@ def test_vprewitt_zeros(): result = F.vprewitt(np.zeros((10, 10)), np.ones((10, 10), bool)) assert (np.all(result == 0)) + def test_vprewitt_mask(): """Vertical prewitt on a masked array should be zero""" np.random.seed(0) @@ -177,6 +295,7 @@ def test_vprewitt_mask(): np.zeros((10, 10), bool)) assert (np.all(result == 0)) + def test_vprewitt_vertical(): """Vertical prewitt on an edge should be a vertical line""" i, j = np.mgrid[-5:6, -5:6] @@ -188,6 +307,7 @@ def test_vprewitt_vertical(): eps = .000001 assert (np.all(np.abs(result[np.abs(j) > 1]) < eps)) + def test_vprewitt_horizontal(): """Vertical prewitt on a horizontal edge should be zero""" i, j = np.mgrid[-5:6, -5:6] From 04f21c58419f2937d3a4eb6c975617ec5c140393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Fri, 12 Oct 2012 19:16:04 +0200 Subject: [PATCH 2/7] Fix dtype and dim note for parameters in doc strings --- skimage/filter/edges.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/skimage/filter/edges.py b/skimage/filter/edges.py index 98e4f600..fa11c69c 100644 --- a/skimage/filter/edges.py +++ b/skimage/filter/edges.py @@ -39,9 +39,9 @@ def sobel(image, mask=None): Parameters ---------- - image : array_like, dtype=float + image : 2-D array Image to process. - mask : array_like, dtype=bool, optional + mask : 2-D array, optional An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result. @@ -68,9 +68,9 @@ def hsobel(image, mask=None): Parameters ---------- - image : array_like, dtype=float + image : 2-D array Image to process. - mask : array_like, dtype=bool, optional + mask : 2-D array, optional An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result. @@ -103,9 +103,9 @@ def vsobel(image, mask=None): Parameters ---------- - image : array_like, dtype=float + image : 2-D array Image to process - mask : array_like, dtype=bool, optional + mask : 2-D array, optional An optional mask to limit the application to a certain area Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result. @@ -138,9 +138,9 @@ def scharr(image, mask=None): Parameters ---------- - image : array_like, dtype=float + image : 2-D array Image to process. - mask : array_like, dtype=bool, optional + mask : 2-D array, optional An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result. @@ -165,9 +165,9 @@ def hscharr(image, mask=None): Parameters ---------- - image : array_like, dtype=float + image : 2-D array Image to process. - mask : array_like, dtype=bool, optional + mask : 2-D array, optional An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result. @@ -200,9 +200,9 @@ def vscharr(image, mask=None): Parameters ---------- - image : array_like, dtype=float + image : 2-D array Image to process - mask : array_like, dtype=bool, optional + mask : 2-D array, optional An optional mask to limit the application to a certain area Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result. @@ -235,9 +235,9 @@ def prewitt(image, mask=None): Parameters ---------- - image : array_like, dtype=float + image : 2-D array Image to process. - mask : array_like, dtype=bool, optional + mask : 2-D array, optional An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result. @@ -260,9 +260,9 @@ def hprewitt(image, mask=None): Parameters ---------- - image : array_like, dtype=float + image : 2-D array Image to process. - mask : array_like, dtype=bool, optional + mask : 2-D array, optional An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result. @@ -295,9 +295,9 @@ def vprewitt(image, mask=None): Parameters ---------- - image : array_like, dtype=float + image : 2-D array Image to process. - mask : array_like, dtype=bool, optional + mask : 2-D array, optional An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result. From 1fbd664d5bad1bc17ff6b856478f05e1215cbf29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 13 Oct 2012 09:17:34 +0200 Subject: [PATCH 3/7] Add reference for scharr operator --- skimage/filter/edges.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/skimage/filter/edges.py b/skimage/filter/edges.py index fa11c69c..f11ae33a 100644 --- a/skimage/filter/edges.py +++ b/skimage/filter/edges.py @@ -156,6 +156,11 @@ def scharr(image, mask=None): vertical Scharrs to get a magnitude that's somewhat insensitive to direction. + References + ---------- + .. [1] D. Kroon, 2009, Short Paper University Twente, Numerical Optimization + of Kernel Based Image Derivatives. + """ return np.sqrt(hscharr(image, mask)**2 + vscharr(image, mask)**2) @@ -186,6 +191,11 @@ def hscharr(image, mask=None): 0 0 0 -3 -10 -3 + References + ---------- + .. [1] D. Kroon, 2009, Short Paper University Twente, Numerical Optimization + of Kernel Based Image Derivatives. + """ image = img_as_float(image) result = np.abs(convolve(image, @@ -221,6 +231,11 @@ def vscharr(image, mask=None): 10 0 -10 3 0 -3 + References + ---------- + .. [1] D. Kroon, 2009, Short Paper University Twente, Numerical Optimization + of Kernel Based Image Derivatives. + """ image = img_as_float(image) result = np.abs(convolve(image, From be6f02bd3d8987323242475845ec0d4731205a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 13 Oct 2012 09:18:11 +0200 Subject: [PATCH 4/7] Fix stylistic indentation --- skimage/filter/edges.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skimage/filter/edges.py b/skimage/filter/edges.py index f11ae33a..f374634e 100644 --- a/skimage/filter/edges.py +++ b/skimage/filter/edges.py @@ -239,9 +239,9 @@ def vscharr(image, mask=None): """ image = img_as_float(image) result = np.abs(convolve(image, - np.array([[ 3, 0, -3], + np.array([[ 3, 0, -3], [10, 0, -10], - [ 3, 0, -3]]).astype(float) / 16.0)) + [ 3, 0, -3]]).astype(float) / 16.0)) return _mask_filter_result(result, mask) From 37ccc805e9a37dd8ce50d60b29525e484fbe4990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 13 Oct 2012 09:19:53 +0200 Subject: [PATCH 5/7] Fix test case doc strings --- skimage/filter/tests/test_edges.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/skimage/filter/tests/test_edges.py b/skimage/filter/tests/test_edges.py index 1edf8914..c16b953d 100644 --- a/skimage/filter/tests/test_edges.py +++ b/skimage/filter/tests/test_edges.py @@ -107,13 +107,13 @@ def test_vsobel_horizontal(): def test_scharr_zeros(): - """Sobel on an array of all zeros""" + """Scharr on an array of all zeros""" result = F.scharr(np.zeros((10, 10)), np.ones((10, 10), bool)) assert (np.all(result == 0)) def test_scharr_mask(): - """Sobel on a masked array should be zero""" + """Scharr on a masked array should be zero""" np.random.seed(0) result = F.scharr(np.random.uniform(size=(10, 10)), np.zeros((10, 10), bool)) @@ -121,7 +121,7 @@ def test_scharr_mask(): def test_scharr_horizontal(): - """Sobel on an edge should be a horizontal line""" + """Scharr on an edge should be a horizontal line""" i, j = np.mgrid[-5:6, -5:6] image = (i >= 0).astype(float) result = F.scharr(image) @@ -132,7 +132,7 @@ def test_scharr_horizontal(): def test_scharr_vertical(): - """Sobel on a vertical edge should be a vertical line""" + """Scharr on a vertical edge should be a vertical line""" i, j = np.mgrid[-5:6, -5:6] image = (j >= 0).astype(float) result = F.scharr(image) @@ -142,13 +142,13 @@ def test_scharr_vertical(): def test_hscharr_zeros(): - """Horizontal sobel on an array of all zeros""" + """Horizontal Scharr on an array of all zeros""" result = F.hscharr(np.zeros((10, 10)), np.ones((10, 10), bool)) assert (np.all(result == 0)) def test_hscharr_mask(): - """Horizontal Sobel on a masked array should be zero""" + """Horizontal Scharr on a masked array should be zero""" np.random.seed(0) result = F.hscharr(np.random.uniform(size=(10, 10)), np.zeros((10, 10), bool)) @@ -156,7 +156,7 @@ def test_hscharr_mask(): def test_hscharr_horizontal(): - """Horizontal Sobel on an edge should be a horizontal line""" + """Horizontal Scharr on an edge should be a horizontal line""" i, j = np.mgrid[-5:6, -5:6] image = (i >= 0).astype(float) result = F.hscharr(image) @@ -167,7 +167,7 @@ def test_hscharr_horizontal(): def test_hscharr_vertical(): - """Horizontal Sobel on a vertical edge should be zero""" + """Horizontal Scharr on a vertical edge should be zero""" i, j = np.mgrid[-5:6, -5:6] image = (j >= 0).astype(float) result = F.hscharr(image) @@ -175,13 +175,13 @@ def test_hscharr_vertical(): def test_vscharr_zeros(): - """Vertical sobel on an array of all zeros""" + """Vertical Scharr on an array of all zeros""" result = F.vscharr(np.zeros((10, 10)), np.ones((10, 10), bool)) assert (np.all(result == 0)) def test_vscharr_mask(): - """Vertical Sobel on a masked array should be zero""" + """Vertical Scharr on a masked array should be zero""" np.random.seed(0) result = F.vscharr(np.random.uniform(size=(10, 10)), np.zeros((10, 10), bool)) @@ -189,7 +189,7 @@ def test_vscharr_mask(): def test_vscharr_vertical(): - """Vertical Sobel on an edge should be a vertical line""" + """Vertical Scharr on an edge should be a vertical line""" i, j = np.mgrid[-5:6, -5:6] image = (j >= 0).astype(float) result = F.vscharr(image) @@ -200,7 +200,7 @@ def test_vscharr_vertical(): def test_vscharr_horizontal(): - """vertical Sobel on a horizontal edge should be zero""" + """vertical Scharr on a horizontal edge should be zero""" i, j = np.mgrid[-5:6, -5:6] image = (i >= 0).astype(float) result = F.vscharr(image) From 239026a19dd65770639a7f22a000961adcb9af14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 13 Oct 2012 09:21:10 +0200 Subject: [PATCH 6/7] Add scharr filter to mask test cases --- skimage/filter/tests/test_edges.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skimage/filter/tests/test_edges.py b/skimage/filter/tests/test_edges.py index c16b953d..628de16d 100644 --- a/skimage/filter/tests/test_edges.py +++ b/skimage/filter/tests/test_edges.py @@ -329,7 +329,7 @@ def test_horizontal_mask_line(): expected[1:-1, 1:-1] = 0.2 # constant gradient for most of image, expected[4:7, 1:-1] = 0 # but line and neighbors masked - for grad_func in (F.hprewitt, F.hsobel): + for grad_func in (F.hprewitt, F.hsobel, F.hscharr): result = grad_func(vgrad, mask) yield assert_close, result, expected @@ -346,7 +346,7 @@ def test_vertical_mask_line(): expected[1:-1, 1:-1] = 0.2 # constant gradient for most of image, expected[1:-1, 4:7] = 0 # but line and neighbors masked - for grad_func in (F.vprewitt, F.vsobel): + for grad_func in (F.vprewitt, F.vsobel, F.vscharr): result = grad_func(hgrad, mask) yield assert_close, result, expected From a8291352e42c7484e9afe9e7fb605a069fdf56da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Wed, 17 Oct 2012 09:00:06 +0200 Subject: [PATCH 7/7] Improve description of scharr and sobel edge filters --- skimage/filter/edges.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skimage/filter/edges.py b/skimage/filter/edges.py index f374634e..fcd9f548 100644 --- a/skimage/filter/edges.py +++ b/skimage/filter/edges.py @@ -35,7 +35,7 @@ def _mask_filter_result(result, mask): def sobel(image, mask=None): - """Calculate the absolute magnitude Sobel to find edges. + """Find the edge magnitude using the Sobel transform. Parameters ---------- @@ -134,7 +134,7 @@ def vsobel(image, mask=None): def scharr(image, mask=None): - """Calculate the absolute magnitude Scharr to find edges. + """Find the edge magnitude using the Scharr transform. Parameters ----------