我试图将骨架化的结果转换为一组线段,其中顶点对应于骨架的接线点。形状不是封闭的多边形,它可能有些嘈杂(段不像应有的那样直接)。
这是一个示例输入图像:
,这是我要检索的点:
我尝试使用Harris Corner detter尝试调整算法的参数后(例如图像底部的角度部分)。以下是结果:
您知道有任何能够执行此操作的方法吗?我使用的是Python,主要是OpenCV和Numpy,但我没有绑定到任何库。提前致谢。
编辑:我对接线点有一些很好的回应,我真的很感激。我还要感谢有关从接线点提取线段的任何解决方案。我认为@nathancy 可以用来通过用交叉点面具减去口罩来提取线段,但是我是没有把握。
I am trying to convert the result of a skeletonization into a set of line segments, where the vertices correspond to the junction points of the skeleton. The shape is not a closed polygon and it may be somewhat noisy (the segments are not as straight as they should be).
Here is an example input image:

And here are the points I want to retrieve:

I have tried using the harris corner detector, but it has trouble in some areas even after trying to tweak the algorithm's parameters (such as the angled section on the bottom of the image). Here are the results:

Do you know of any method capable of doing this? I am using python with mostly OpenCV and Numpy but I am not bound to any library. Thanks in advance.
Edit: I've gotten some good responses regarding the junction points, I am really grateful. I would also appreciate any solutions regarding extracting line segments from the junction points. I think @nathancy's answer could be used to extract line segments by subtracting the masks with the intersection mask, but I am not sure.
发布评论
评论(2)
我的方法是基于我以前的答案在这里。它涉及卷动与特殊内核的图像。该卷积确定了线的终点以及交叉点。这将导致一个点掩模,其中包含与您要寻找的点相匹配的像素。之后,应用一点形态以加入可能的重复点。该方法对于骨骼产生的角度明智。
这是代码:
到目前为止,我将骨骼图像与我的特殊内核一起卷积。您可以检查产生的图像并搜索拐角和交叉点的数值。
这是到目前为止的输出:
接下来,确定角落或交集。这个位很棘手,因为阈值值直接取决于骨架图像,有时不会产生好(接近直的)角:
这是二进制掩码:
让我们扩张以加入近距离点:
这是输出:
现在简单提取外部轮廓。获取它们的边界框并计算其质心:
这就是结果。错过了一些角落,您可能会在计算骨架之前改进解决方案。
My approach is based on my previous answer here. It involves convolving the image with a special kernel. This convolution identifies the end-points of the lines, as well as the intersections. This will result in a points mask containing the pixel that matches the points you are looking for. After that, apply a little bit of morphology to join possible duplicated points. The method is sensible to the corners produced by the skeleton.
This is the code:
So far I convolved the skeleton image with my special kernel. You can inspect the image produced and search for the numerical values at the corners and intersections.
This is the output so far:
Next, identify a corner or an intersection. This bit is tricky, because the threshold value depends directly on the skeleton image, which sometimes doesn't produce good (close to straight) corners:
This is the binary mask:
Let's dilate to join close points:
This is the output:
Now simple extract external contours. Get their bounding boxes and calculate their centroid:
This is the result. Some corners are missed, you might one to improve the solution before computing the skeleton.
这是一种简单的方法,这个想法是:
获取二进制图像。加载图像,转换为灰度, gaussian blur”> gaussian blur ,然后 otsu的阈值。
获得水平和垂直线蒙版。用
cv2.getStructuringElement
然后执行查找关节。我们
cv2.bitwise_and
两个蒙版一起获取关节。这个想法是两个口罩上的交点点是关节。在关节面膜上找到质心。我们查找轮廓然后计算
查找剩余的端点。端点与十字路口无关,因此为了找到这些端点,我们可以使用 shi-tomasi corner corner detter
和垂直线掩模的
结果
水平 i.sstatic.net/gaiyn.png“ rel =“ nofollow noreferrer”>
”
Here's a simple approach, the idea is:
Obtain binary image. Load image, convert to grayscale, Gaussian blur, then Otsu's threshold.
Obtain horizontal and vertical line masks. Create horizontal and vertical structuring elements with
cv2.getStructuringElement
then performcv2.morphologyEx
to isolate the lines.Find joints. We
cv2.bitwise_and
the two masks together to get the joints. The idea is that the intersection points on the two masks are the joints.Find centroid on joint mask. We find contours then calculate the centroid.
Find leftover endpoints. Endpoints do not correspond to an intersection so to find those, we can use the Shi-Tomasi Corner Detector
Horizontal and vertical line masks
Results (joints in green and endpoints in blue)
Code