From a7527adf31e464b93daaa2d4d8da6db70187aba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 17 Nov 2012 22:27:11 +0100 Subject: [PATCH 1/2] Add example for hough_peaks function --- doc/examples/plot_hough_transform.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/doc/examples/plot_hough_transform.py b/doc/examples/plot_hough_transform.py index 5416d662..12931c74 100644 --- a/doc/examples/plot_hough_transform.py +++ b/doc/examples/plot_hough_transform.py @@ -59,7 +59,7 @@ References ''' -from skimage.transform import hough, probabilistic_hough +from skimage.transform import hough, hough_peaks, probabilistic_hough from skimage.filter import canny from skimage import data @@ -81,11 +81,11 @@ h, theta, d = hough(image) plt.figure(figsize=(8, 4)) -plt.subplot(121) +plt.subplot(131) plt.imshow(image, cmap=plt.cm.gray) plt.title('Input image') -plt.subplot(122) +plt.subplot(132) plt.imshow(np.log(1 + h), extent=[np.rad2deg(theta[-1]), np.rad2deg(theta[0]), d[-1], d[0]], @@ -94,6 +94,14 @@ plt.title('Hough transform') plt.xlabel('Angles (degrees)') plt.ylabel('Distance (pixels)') +plt.subplot(133) +plt.imshow(image, cmap=plt.cm.gray) +rows, cols = image.shape +for _, angle, dist in zip(*hough_peaks(h, theta, d)): + y0 = (dist - 0 * np.cos(angle)) / np.sin(angle) + y1 = (dist - cols * np.cos(angle)) / np.sin(angle) + plt.plot((0, cols), (y0, y1), '-r') +plt.axis((0, cols, rows, 0)) # Line finding, using the Probabilistic Hough Transform @@ -121,4 +129,3 @@ for line in lines: plt.title('Lines found with PHT') plt.axis('image') plt.show() - From 49e06c97552173a42071be424a017455f283f8b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Mon, 3 Dec 2012 14:37:26 +0100 Subject: [PATCH 2/2] Add title to hough peak detection example plot --- doc/examples/plot_hough_transform.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/examples/plot_hough_transform.py b/doc/examples/plot_hough_transform.py index 12931c74..b74132da 100644 --- a/doc/examples/plot_hough_transform.py +++ b/doc/examples/plot_hough_transform.py @@ -102,6 +102,7 @@ for _, angle, dist in zip(*hough_peaks(h, theta, d)): y1 = (dist - cols * np.cos(angle)) / np.sin(angle) plt.plot((0, cols), (y0, y1), '-r') plt.axis((0, cols, rows, 0)) +plt.title('Detected lines') # Line finding, using the Probabilistic Hough Transform @@ -126,6 +127,6 @@ for line in lines: p0, p1 = line plt.plot((p0[0], p1[0]), (p0[1], p1[1])) -plt.title('Lines found with PHT') +plt.title('Probabilistic Hough') plt.axis('image') plt.show()