我手头有一个创建的函数文件,它是在图像中画线,[img]=drawline(point1,point2,color,img)
。它用于连接图像内的任意两点。我被要求在图像中创建 voronoi 图(不使用绘图功能)。目前,我正在尝试显示图像中的线条,但我不知道如何获取多边形边的顶点。
我一直在使用一些测试代码:
x=[50 70 70 30 40 ];% this is just some simple values for testing,
y=[50 30 90 30 80 ];% in further stage, i plan to use `x=rand(n,1)*200`.
img=zeros(200,200,3);
color=[255 0 0];
[vx,vy]=voronoi(x,y);
我只知道上面,接下来我想我需要使用for loop
将顶点对齐。只是不知道如何开始。如果我需要在图像(像素坐标)中显示它们,我也陷入如何解决负面和无限问题的困境。
假设你有这个drawline
在图像中绘制线条的函数,这就是在一组点的 Voronoi 图的边缘上循环的方法:
%# set of points and voronoi diagram
X = rand(10,1)*200; Y = rand(10,1)*200;
[vx,vy] = voronoi(X,Y);
%# vertices connecting the edges
p1 = [vx(1,:);vy(1,:)]; % columns are "from" points
p2 = [vx(2,:);vy(2,:)]; % columns are "to" points
%# draw edges on top of image matrix
img = zeros(200,200,3);
clr = [255 0 0];
for i=1:size(vx,2)
img = drawline(p1(:,i), p2(:,i), clr, img);
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)