简体   繁体   中英

How to get extream x,y coordinates for hough line peaks with skimage

h, theta, d = transform.hough_line(outlines)
for acum, angle, dist in zip(*transform.hough_line_peaks(h, theta, d)):
    y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
    y1 = (dist - outlines.shape[1] * np.cos(angle)) / np.sin(angle)
    x0 = ...
    x1 = ...
    rr,cc,_ = draw.line_aa(x0,y0,x1,y1)

What I want is the x0 and x1 values between the range of my outline shape, that is 640,640 (2D). And I want to scale the y0 and y1 to the size of my outline.shape .

The y0, y1 coordinate that you calculate with that formula correspond to where the line intersects the edges of your image. That is why it includes 0 and outlines.shape[1] .

y0 corresponds to the row where the line intersects column 0, hence 0 * cos(angle) .

y1 corresponds to the row where the line intersects the last column of your image, ie its width (which is outlines.shape[1] )

So you can draw a line from (0, y0) to (width, y1) to emphasize the detected lines. Use, for example outlines[line(0, y0, width-1, y1] = 1 . Note I put width - 1 because indexing starts from 0 and width is out of bounds. This is not the case in your formula because it is subtracted from dist

This tutorial illustrates well how it works and how to add the discovered lines to your image (in the first part). Replace the uninspired X-shaped image with an image of your choice and you will see the lines. Your image should ideally be binarised and have not too many points, so try passing it through and edge detector (Canny) or a skeletonization procedure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM