【问题标题】:Matlab: How to derive the vertices (coordinates) of polygons in voronoi diagram?Matlab:如何在voronoi图中导出多边形的顶点(坐标)?
【发布时间】:2011-10-19 09:26:15
【问题描述】:

我手头有一个创建的函数文件,用于在图像中画线,[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 来排列顶点。只是不知道如何开始。如果我需要在图像(像素坐标)中显示它们,我也陷入了如何解决负面和无限问题。

【问题讨论】:

    标签: image matlab voronoi


    【解决方案1】:

    假设您有这个在图像中绘制线条的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
    

    【讨论】:

    • 短而强的循环。实际上,我一直对负值的问题感到很困惑。一旦我 voronoi(x,y),我肯定有一些负坐标和 [vx,vy] 的 inf,椭圆也是如此(你建议的函数 'calculateEllipse.m')。我构成椭圆的点还包括负值。对于我的工作,我需要做的是最终让它们显示在图像中。而对于图像,它只接受正整数。你对此有什么想法吗?
    • @Ivy:也许你可以使用某种line clipping 算法。至于省略号,我已经在previous answer 中提出了解决方案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-27
    • 2019-12-27
    • 2012-04-25
    • 2015-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多