IMG: The image to be detected.
Threshold: Threshold value, first entry, default = 10
Line_length: The shortest line length detected, default is 50
Line_gap: The maximum gap between lines. Increase this value to merge broken lines. Default is 10
Return:
Lines: A list of lines, formatted as ((x0, y0), (x1, y0)), indicating the start and end points.
Below, we use the canny operator to extract the edges and then detect which edges are straight lines?
Import Skimage.transform as Stimport Matplotlib.pyplot as Pltfrom skimage import data,feature# use probabilistic Hough Trans Form.image = Data.camera () edges = Feature.canny (image, sigma=2, low_threshold=1, high_threshold=25) lines = St.probabilistic_hough_line (edges, threshold=10, line_length=5,line_gap=3) # Create a display window. Fig, (ax0, ax1, ax2) = Plt.subplots (1, 3, figsize= (6)) Plt.tight_layout () #显示原图像ax0. Imshow (image, Plt.cm.gray) ax0.set_title (' Input image ') ax0.set_ Axis_off () #显示canny边缘ax1. Imshow (edges, Plt.cm.gray) ax1.set_title (' Canny edges ') Ax1.set_axis_off () # Plot all the straight lines with plot ax2.imshow (edges * 0) for the line in lines: p0, p1 = ((Ax2.plot], p0[0]) , P1[0, C Ol2 = Image.shapeax2.axis ((0, col2, row2, 0)) Ax2.set_title (' Probabilistic Hough ') Ax2.set_axis_off () plt.show ()
Python-anaconda Practice candy operator for edge extraction, and then use Hough Transform to detect line edges