【问题标题】:How to detect hand drawn lines using hough transform in matlab?如何在matlab中使用霍夫变换检测手绘线?
【发布时间】:2016-07-28 21:51:16
【问题描述】:

我正在做一个 matlab 图像处理项目,它基本上从手绘电路图的图像中提取组件和连接。

在预处理得到骨架图像后,我尝试使用霍夫变换来检测线条,以便识别角点和连接路径。

代码如下:

[H,T,R] = hough(im);
peaks = houghpeaks(H,50,'Threshold',ceil(0.3*max(H(:))));
lines = houghlines(im, T,R,peaks, 'Fillgap', 20, 'MinLength', 20);

figure; imshow(im);
title('Lines detected');
hold on;
for l=1:length(lines)
    xy = [lines(l).point1; lines(l).point2];
    if ((lines(l).theta == 0)||(lines(l).theta >= 355 && lines(l).theta < 5)) || (lines(l).theta < 95 && lines(l).theta > 85) % detect only approx. horizontal and vertical lines 
        plot(xy(:,1),xy(:,2), 'LineWidth', 2);
    end
end

这是我执行时得到的输入和输出:

我需要检测几乎水平或垂直的所有线段,具有最小长度,由于手绘性质而存在一些不规则性。

在给定的屏幕截图中,输出图像仅显示少数检测到的线条,并且部分线条被部分检测到。它实际上应该检测用于连接组件的所有电线

如何调整霍夫变换函数或使用任何其他方法来实现此要求?

【问题讨论】:

    标签: matlab image-processing hough-transform image-morphology


    【解决方案1】:

    (lines(l).theta &gt;= 355 &amp;&amp; lines(l).theta &lt; 5) 是不可能的。所以唯一接受的 theta 值是 0 和 [86,94]。

    说实话,我完全不明白为什么会给出水平线和垂直线 - 我认为结果会以弧度表示,显然 86 到 94 弧度是没有意义的。

    话虽如此,您不仅要检查 0 度/0 弧度,还要检查 180 度/pi 弧度,同样检查 270 度 = 3/2 pi = -1/2 pi。

    【讨论】:

      猜你喜欢
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-03
      相关资源
      最近更新 更多