From 5f5af645514bfeda5789870e254e491e18796dc1 Mon Sep 17 00:00:00 2001 From: Julius Bier Kirekgaard Date: Fri, 28 Aug 2015 20:08:11 +0100 Subject: [PATCH 1/4] Example for hough_circle --- skimage/transform/hough_transform.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/skimage/transform/hough_transform.py b/skimage/transform/hough_transform.py index 363caf2e..e0872a30 100644 --- a/skimage/transform/hough_transform.py +++ b/skimage/transform/hough_transform.py @@ -148,6 +148,27 @@ def hough_circle(image, radius, normalize=True, full_output=False): Hough transform accumulator for each radius. R designates the larger radius if full_output is True. Otherwise, R = 0. + + Examples + -------- + >>> from skimage.transform import hough_circle + >>> img = np.zeros((100,100),dtype=np.bool_) + >>> X,Y = np.meshgrid(np.arange(100),np.arange(100)) + >>> x0,y0,radius = 20,35,23 + >>> circle = np.abs((X-x0)**2+(Y-y0)**2-radius**2)<5**2 + >>> img[circle] = 1 + >>> # Find position of circle from known radius: + >>> res = hough_circle(img,np.array([radius]))[0,:,:] + >>> y,x = np.unravel_index(np.argmax(res),res.shape) + >>> x,y + (20, 35) + >>> # Find position and radius by trying a range of radii: + >>> radii_range = np.arange(5,50) + >>> res = hough_circle(img,radii_range) + >>> ridx,y,x = np.unravel_index(np.argmax(res),res.shape) + >>> x,y,radii_range[ridx] + (20, 35, 23) + """ return _hough_circle(image, radius.astype(np.intp), normalize=normalize, full_output=full_output) From 3c41e75b22a3295e104f96b06cdb965e85ef3cd2 Mon Sep 17 00:00:00 2001 From: Julius Bier Kirekgaard Date: Fri, 28 Aug 2015 20:46:14 +0100 Subject: [PATCH 2/4] Added whitespace to comply with pep8 --- skimage/transform/hough_transform.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/skimage/transform/hough_transform.py b/skimage/transform/hough_transform.py index e0872a30..1564fb8d 100644 --- a/skimage/transform/hough_transform.py +++ b/skimage/transform/hough_transform.py @@ -152,21 +152,21 @@ def hough_circle(image, radius, normalize=True, full_output=False): Examples -------- >>> from skimage.transform import hough_circle - >>> img = np.zeros((100,100),dtype=np.bool_) - >>> X,Y = np.meshgrid(np.arange(100),np.arange(100)) - >>> x0,y0,radius = 20,35,23 + >>> img = np.zeros((100, 100), dtype=np.bool_) + >>> X, Y = np.meshgrid(np.arange(100), np.arange(100)) + >>> x0, y0, radius = 20, 35, 23 >>> circle = np.abs((X-x0)**2+(Y-y0)**2-radius**2)<5**2 >>> img[circle] = 1 >>> # Find position of circle from known radius: - >>> res = hough_circle(img,np.array([radius]))[0,:,:] - >>> y,x = np.unravel_index(np.argmax(res),res.shape) - >>> x,y + >>> res = hough_circle(img, np.array([radius]))[0, :, :] + >>> y, x = np.unravel_index(np.argmax(res), res.shape) + >>> x, y (20, 35) >>> # Find position and radius by trying a range of radii: - >>> radii_range = np.arange(5,50) - >>> res = hough_circle(img,radii_range) - >>> ridx,y,x = np.unravel_index(np.argmax(res),res.shape) - >>> x,y,radii_range[ridx] + >>> radii_range = np.arange(5, 50) + >>> res = hough_circle(img, radii_range) + >>> ridx, y, x = np.unravel_index(np.argmax(res), res.shape) + >>> x, y, radii_range[ridx] (20, 35, 23) """ From 002fc70759fd482ae41ae00797c76e4b7758ca63 Mon Sep 17 00:00:00 2001 From: Julius Bier Kirekgaard Date: Fri, 28 Aug 2015 21:04:52 +0100 Subject: [PATCH 3/4] Shorter hough_circle example --- skimage/transform/hough_transform.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/skimage/transform/hough_transform.py b/skimage/transform/hough_transform.py index 1564fb8d..56adcfb2 100644 --- a/skimage/transform/hough_transform.py +++ b/skimage/transform/hough_transform.py @@ -152,22 +152,14 @@ def hough_circle(image, radius, normalize=True, full_output=False): Examples -------- >>> from skimage.transform import hough_circle + >>> from skimage.draw import circle_perimeter >>> img = np.zeros((100, 100), dtype=np.bool_) - >>> X, Y = np.meshgrid(np.arange(100), np.arange(100)) - >>> x0, y0, radius = 20, 35, 23 - >>> circle = np.abs((X-x0)**2+(Y-y0)**2-radius**2)<5**2 - >>> img[circle] = 1 - >>> # Find position of circle from known radius: - >>> res = hough_circle(img, np.array([radius]))[0, :, :] - >>> y, x = np.unravel_index(np.argmax(res), res.shape) - >>> x, y - (20, 35) - >>> # Find position and radius by trying a range of radii: - >>> radii_range = np.arange(5, 50) - >>> res = hough_circle(img, radii_range) - >>> ridx, y, x = np.unravel_index(np.argmax(res), res.shape) - >>> x, y, radii_range[ridx] - (20, 35, 23) + >>> rr, cc = circle_perimeter(25, 35, 23) + >>> img[rr, cc] = 1 + >>> try_radii = np.arange(5, 50) + >>> res = hough_circle(img, try_radii) + >>> ridx, r, c = np.unravel_index(np.argmax(res), res.shape) + (25, 35, 23) """ return _hough_circle(image, radius.astype(np.intp), From b5fd7bc885bc9d2b5def3704b19cb54ef03460f4 Mon Sep 17 00:00:00 2001 From: Julius Bier Kirekgaard Date: Fri, 28 Aug 2015 21:09:42 +0100 Subject: [PATCH 4/4] Fixed forgotten output for docstring example --- skimage/transform/hough_transform.py | 1 + 1 file changed, 1 insertion(+) diff --git a/skimage/transform/hough_transform.py b/skimage/transform/hough_transform.py index 56adcfb2..200aa5dc 100644 --- a/skimage/transform/hough_transform.py +++ b/skimage/transform/hough_transform.py @@ -159,6 +159,7 @@ def hough_circle(image, radius, normalize=True, full_output=False): >>> try_radii = np.arange(5, 50) >>> res = hough_circle(img, try_radii) >>> ridx, r, c = np.unravel_index(np.argmax(res), res.shape) + >>> r, c, try_radii[ridx] (25, 35, 23) """