如何在matlab中沿同一方向连接两条虚线

How do I connect two broken lines along the same direction in matlab

我正在尝试 select 基于用户 selection 的容器分支。
我已经提取了中心线并删除了有很大间隙的分支点。我想做的是,如果用户点击一艘船作为起点,那么它将一直追踪直到遇到一个分支:如果它是一个 3 线交叉,那么两条线都属于这个分支。如果是 4 线交叉,则垂直线属于同一个分支,其他水平线属于另一个分支,因此不是 selected。

如何做到这一点?这就是我想象中的结果..

我认为我使用 imerode and thinning 得到了不错的结果 这些值是通过反复试验获得的,因此这可能不是通用的解决方案。您还会注意到 "tree" 的顶部消失了。我只包含了最后一张图片。

%if your image isn't already binary turn it into a logical array
bwim = im2bw(im);

%13 came by trial and error, you can also play with the shape and use something
%besides a disk
thick = imerode(bwim,strel('disk',13));

%the infinite means do untill no changes occur. we use ~thick becasue thin
%works on 1 pixels, not 0's. we then invert the output of bwmorph to get our
%image back to normal (0 foregroun 1 background)
thinned = ~bwmorph(~thick,'thin',inf);

figure(1);imshow(bwim);title('original');
figure(2);imshow(thick);title('after erosion');
figure(3);imshow(thinned);title('after thining');

这看起来不错,但通常最好从高质量图像开始,而不是从劣质图像开始并进行大量 post 处理。我建议对感兴趣的区域应用对比度增强(例如 histogram equalization 是一个简单的选择)。在执行对比度增强之前,您可能必须裁剪掉黑色背景(或者如果您不能用图像的平均灰度值替换它)。抽取你的静脉后,也许你甚至不需要连接碎片。

祝你好运