如何在matlab中使用hough变换检测手绘线? [英] How to detect hand drawn lines using hough transform in matlab?

查看:189
本文介绍了如何在matlab中使用hough变换检测手绘线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working on a matlab image processing project which basically extracts components and connections from an image of hand-drawn circuit diagram.

预处理并获得骨架图像后,我尝试使用Hough变换检测线条,以便我可以识别角点和连接路径。

After preproccessing and obtaining skeleton image, I tried to use Hough transform to detect the lines so that i can identify corners and connection paths.

以下是代码:

[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

这是我执行时输入和输出:

This is the input and output that i got when executing:

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

I need to detect all the line segments, that are almost horizontal or vertical, having minimum length, with some irregularities due to hand drawn nature.

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

In given screenshot, the output image shows only few detected lines, and some of lines are partially detected. It should actually detect all the wires used to connect components

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

How can i tune Hough transform functions or use any other methods to achieve this requirement ?

推荐答案

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

(lines(l).theta >= 355 && lines(l).theta < 5) is impossible.So the only accepted theta values are 0 and [86,94].

老实说,我并不完全理解为什么会给出水平和垂直线 - 我认为结果是弧度,显然是86弧度到94弧度毫无意义。

To be honest, I don't entire understand why that gives horizontal and vertial lines - I'd think the result would be in radians and obviously 86 radians to 94 radians makes no sense.

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

Having said that, you not only want to check for 0 degrees / 0 radians but also 180 degrees / pi radians, and the same for 270 degrees = 3/2 pi = -1/2 pi.

这篇关于如何在matlab中使用hough变换检测手绘线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆