From 56fe676c66a8f6c75e0b4b90f4170cf5bb6af5fa Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 16 Jul 2011 14:15:39 -0500 Subject: [PATCH] ENH: Add hough transform plot. --- doc/source/plots/hough_tf.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 doc/source/plots/hough_tf.py diff --git a/doc/source/plots/hough_tf.py b/doc/source/plots/hough_tf.py new file mode 100644 index 00000000..663edff1 --- /dev/null +++ b/doc/source/plots/hough_tf.py @@ -0,0 +1,30 @@ +import numpy as np +import matplotlib.pyplot as plt + +from scikits.image.transform import hough + +img = np.zeros((100, 150), dtype=bool) +img[30, :] = 1 +img[:, 65] = 1 +img[35:45, 35:50] = 1 +for i in range(90): + img[i, i] = 1 +img += np.random.random(img.shape) > 0.95 + +out, angles, d = hough(img) + +plt.subplot(1, 2, 1) + +plt.imshow(img, cmap=plt.cm.gray) +plt.title('Input image') + +plt.subplot(1, 2, 2) +plt.imshow(out, cmap=plt.cm.bone, + extent=(d[0], d[-1], + np.rad2deg(angles[0]), np.rad2deg(angles[-1]))) +plt.title('Hough transform') +plt.xlabel('Angle (degree)') +plt.ylabel('Distance (pixel)') + +plt.subplots_adjust(wspace=0.4) +plt.show()