mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-04 16:31:50 +08:00
Add example for hough_peaks function
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user