Matlab 中的边链接

问题描述

我正在尝试链接图像中的边缘,如下图所示:

Broken Edges

我尝试过使用膨胀/侵蚀操作,但结果并不好。还有其他方法可以链接边缘吗?

这是原图:

Original Image

解决方法

您获得的结果很可能足以应用霍夫变换,这将确定图像中最重要的八条线。

我不知道您的所有图像是否都相似,但在您展示的示例中,很容易将灰线与绿色背景分开。例如,下面的代码(使用 DIPimage,但也很容易用其他工具实现)将相对明亮的灰色与任何深色或彩色的东西区分开来:

align_plots

output of first code snippet

接下来,一个拉普拉斯高斯滤波器(它是一个线检测器),一些阈值刚好高于零,并且只选择较大的对象会导致检测到的线:

img = readim('https://i.stack.imgur.com/vmBiF.jpg');
img = colorspace(img,'hsv');
img = (0.5-img{2})*img{3}; % img{2} is the saturation channel,img{3} is the value (intensity) channel
img = clip(img);           % set negative values to 0

output of second code snippet

不用说,这在计算上比运行 U-Net 要便宜得多。