[英]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). 我想要的是我的轮廓形状范围之间的
x0
和x1
值,即640,640(2D)。 And I want to scale the y0
and y1
to the size of my outline.shape
. 我想将
y0
和y1
缩放到outline.shape
的大小。
The y0, y1
coordinate that you calculate with that formula correspond to where the line intersects the edges of your image. 使用该公式计算的
y0, y1
坐标对应于线与图像边缘相交的位置。 That is why it includes 0
and outlines.shape[1]
. 这就是它包含
0
和outlines.shape[1]
。
y0
corresponds to the row where the line intersects column 0, hence 0 * cos(angle)
. y0
对应于线与列0相交的行,因此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]
) y1
对应于线与图像的最后一列相交的行,即其宽度(即outlines.shape[1]
)
So you can draw a line from (0, y0)
to (width, y1)
to emphasize the detected lines. 因此,您可以从
(0, y0)
到(width, y1)
绘制一条线来强调检测到的线条。 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
使用,例如
outlines[line(0, y0, width-1, y1] = 1
注意我放宽width - 1
因为索引从0开始, width
超出范围。在你的公式中不是这种情况,因为它是从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.
用您选择的图像替换未出现的X形图像,您将看到线条。 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.
理想情况下,您的图像应该被二值化并且没有太多点,因此请尝试将其传递给边缘检测器(Canny)或骨架化过程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.