Reputation: 145
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
.
Upvotes: 3
Views: 1720
Reputation: 4000
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, i.e. 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.
Upvotes: 1