如何用 Matlab 连接图像中的断开点?

How to connect the disconnected-points in image with Matlab?

这是一个更具体的复杂设置问题。我已经计算了所有 1 像素到其最近的原始图像 0 像素的距离,并转换为具有如下所示局部最大值的图像:

我使用以下代码从此转换后的矩阵中提取局部最大值:

loc_max = imregionalmax(loc,4);
figure;imshow(loc_max)

loc_max 给出了那些局部最大值点的断开点。尝试了很多方法来连接它们,但还没有达到预期的效果。

这是我的一个想法:

[yy xx]=find(loc_max ==1);
d = [];
dmin = [];
idx = [];
for i = 1: size(yy,1)
    for j = 1:size(xx,1)
        if i ~= j
            d(j) = sqrt(sum(bsxfun(@minus,[yy(j) xx(j)],[yy(i) xx(i)]).^2,2));
            %calculate the distance between current 1-pixel in loc_max and all other local maxima pixels in loc_max.
        end        
    end    
    [dmin(i),idx(i)] = min(d(:));%find the minimum distance between current 1-pixel to others
end

我试图在loc_max中找到与当前loc_max中的1像素最近的1像素,然后将它们连接起来。但这还不是解决方案。因为如果前一个像素是当前像素的最近像素,它不会连接到下一个 1 像素。

此外,我想保留两个断开连接的 1 像素之间连线上的那些 0 像素的像素信息。我希望以后能够用这个简化的骨架重建整个图像。

如有任何帮助,我们将不胜感激!

我试过腐蚀和扩张(就像 Ander Biguri 建议的那样)。
我尝试将内核的角度设置为正确的。

检查以下内容:

%Fix the input (remove JPEG artifacts and remove while margins)
%(This is not part of the solution - just a little cleanup).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I = imread('https://i.stack.imgur.com/4L3fP.jpg'); %Read image from imgur.
I = im2bw(I);
[y0, x0] = find(I == 0);
[y1, x1] = find(I == 0, 1, 'last');
I = I(y0:y1, x0:x1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

se0 = strel('disk', 3);
J = imdilate(I, se0); %Dilate - make line fat

se1 = strel('line', 30, 150); %150 degrees.
se2 = imdilate(se1.getnhood , se0); %Create 150 degrees fat line
J = imclose(J, se2); %Close - (dilate and erode)

se1 = strel('line', 30, 140); %140 degrees.
se2 = imdilate(se1.getnhood , se0);
J = imclose(J, se2);

se1 = strel('line', 80, 60); %60 degrees.
se2 = imdilate(se1.getnhood , se0); %Create 60 degrees fat line
J = imclose(J, se2);

se4 = strel('disk', 2);
J = imerode(J, se4); %Erode - make lines little thinner.

figure;imshow(J);

结果:

你觉得还好吗?


Ander Biguri 因以下解决方案而获得荣誉:

J = bwmorph(J,'skel',Inf);