如何从Voronoi图中剪掉一些不需要的分支?

How to prune some unnecessary branches from the Voronoi diagram?

我使用以下 MATLAB 代码生成了 Voronoi 图。问题是在输出图像中我得到了一些我想删除的无用线条。无用的线,我的意思是那些用紫色圈起来的线,也就是直接连接到多边形的线。我只想要输出图像中的绿色。有人可以帮我吗?提前致谢。

clc; clear all; close all;

%% Input Map
RGB = imread('mappa3.png');
figure('Position',[100 0 600 700],'color','k')
imagesc(RGB);
axis image
title('Input Map','color','w');
axis off
set(gcf, 'InvertHardCopy', 'off');
hold off;

%% Convert to binary image
I = rgb2gray(RGB);
binaryImage = im2bw(RGB, 0.3);
sz  = size(binaryImage);

%% Pose
% Initial Pose
xs = 270; ys = 296; % valori iniziali 55 e 33
% Goal Pose
xg = 50; yg = 50; % valori iniziali 50 e 50
% Pose Matrix
pose = zeros(sz(1),sz(2));
pose(ys,xs) = 1;
pose(yg,xg) = 1;

%% Voronoi Road Map
figure('Position',[100 0 600 700],'color','k');
hold on;
set(gcf, 'InvertHardCopy', 'off');
sk = 1;
for i = 1:sz(1)
  for j = 1:sz(2)
    if(binaryImage(i,j) == 1 )
      xv(sk) = j;
      yv(sk) = i;
      sk = sk+1;
    end
  end
end
[vrx,vry]  = voronoi(xv,yv);
set(gca,'YDir','Reverse');
plot(xv,yv,'y.',vrx,vry,'b-')
axis tight
%axis([1 sz(2) 1 sz(1) ]) ;
axis image
title({'Voronoi Road Map';'* - Represents Starting and Goal Position '},'color','w');
axis off

spy(pose,'*r')   

您将每个单独的像素作为单元质心,因此 Voronoi 图环绕每个单独的像素。您想将每组连接的像素(多边形)作为质心。最重要的是,以某种方式包括这些像素组的大小,以便 Voronoi 图不会穿过它们。

您可以通过计算背景的骨架来完成所有这些,如下所示:

img = imread('https://i.stack.imgur.com/TbmKp.png');
background = img(:,:,1)==0;
voronoi = bwskel(background,'MinBranchLength',1e6);