0
我正在研究一个基本上从手绘电路图的图像中提取组件和连接的matlab图像处理项目。如何在matlab中使用hough变换检测手绘线条?
经过预处理和获得骨架图像后,我尝试使用霍夫变换来检测线条,以便我可以识别角点和连接路径。
下面是代码:
[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
这是我上执行时得到的输入和输出:
我需要检测所有的线段,是几乎水平的或垂直的,具有最小长度,由于手绘本质而具有一些不规则性。
在给定的屏幕截图中,输出图像只显示几条检测线,部分线被部分检测到。它应该实际检测用于连接组件的所有电线
如何调整Hough变换函数或使用任何其他方法来实现此要求?