5

是否有任何算法来实现限制椭圆的 Voronoi 图?该图看起来像这里的图片voronoi diagram of ellipses

http://www.loria.fr/~tzoumas/vorell/vorell01.png

任何人都可以分享一些与它相关的链接、教程、代码等吗?

提前致谢。

4

4 回答 4

6

这是一个算法,它使用距离变换分水岭算法来绘制椭圆的 Voronoi 图。

%# first, define some ellipses (for simplicity, I use 0/90 orientation)
ellipses = [10,20,5,10;30,10,10,7;40,40,8,3];

%# put the ellipses into an image (few pixels, therefore pixelated)
img = false(50);
[xx,yy]=ndgrid(1:50,1:50);
for e = 1:size(ellipses,1),img = img | (xx-ellipses(e,1)).^2/ellipses(e,3)^2 + (yy-ellipses(e,2)).^2/ellipses(e,4)^2 <= 1;end

在此处输入图像描述

%# perform the distance transform
dt = bwdist(img);

在此处输入图像描述

%# apply the watershed algorithm. 
%# ws==0 are the lines for the Voronoi diagram
ws = watershed(dt);

%# create a RGB image and display
%# note: for yellow lines, replace the last
%# "ws==0" by "zeros(size(ws))", so that you
%# only put ws into the red and green channel (=yellow)
rgb = cat(3,ws==0,ws==0,ws==0)); 
%# add the ellipses into the red channel
rgb(:,:,1) = rgb(:,:,1) | img;
imshow(rgb)

在此处输入图像描述

于 2011-10-25T01:06:55.613 回答
2

以防万一,这是 Mathematica 帮助系统中的一个示例:

(*Generate ellipses*)
p= Rasterize@Graphics@Table[
          Rotate[
              Disk[RandomReal[10, 2],          (*Rnd position*)
                   RandomReal[{.3, 1.5}, 2]],  (*Rnd radii*)
          RandomReal[Pi]], {i, 10}]            (*Rnd rotation*)

(*Compute Voronoi*)

LaplacianGaussianFilter[DistanceTransform[p], 2] // ImageAdjust

在此处输入图像描述

这不是一个精确的计算,但对于实际使用来说足够公平。

于 2011-10-26T02:23:37.310 回答
1

根据您最近提出的问题,我了解到您一直致力于在 RGB 图像上绘制栅格化椭圆。您希望能够指定椭圆的位置、形状和颜色。您希望椭圆在边界处被剪裁,并且不重叠。现在您正在寻找以类似于 Voronoi 图的方式(但使用椭圆而不是点)来划分空间的线。

对于这个特定的问题,正如@Jonas所示,解决方案是将距离变换与分水岭算法一起使用。

我想我会继续我之前的示例,并用 Jonas 的想法对其进行扩展,以展示整个过程。希望你觉得它有用..

该代码使用该calculateEllipse函数来计算构成椭圆的点的坐标,以及imoverlay将图像的指定像素设置为某些选定颜色的函数。

%# color image (canvas to draw on)
I = imread('pears.png');
sz = size(I);

%# random ellipses
num = 20;
centers = bsxfun(@times, rand(num,2), sz([2 1]));   %# center x/y-coords
radii = bsxfun(@times, rand(num,2), [300 50])+10;   %# major/minor axis length
angles = rand(num,1) .* 360;                        %# angle of rotation
ex = cell(num,1);                                   %# vertices x-coords
ey = cell(num,1);                                   %# vertices y-coords

%# label image, used to hold rasterized ellipses
L = zeros(sz(1),sz(2));

%# randomly place ellipses one-at-a-time, skip if overlaps previous ones
flag = false(num,1);
for i=1:num
    %# ellipse we would like to draw directly on image matrix
    [ex{i},ey{i}] = calculateEllipse(centers(i,1),centers(i,2), ...
        radii(i,1),radii(i,2), angles(i), 100);

    %# create mask for image pixels inside the ellipse polygon
    mask = poly2mask(ex{i},ey{i}, sz(1),sz(2));

    %# check if there is no existing overlapping ellipse
    if all( L(mask)==0 )
        %# use the mask to place the ellipse in the label image
        L(mask) = sum(flag)+1;    %# assign value using an increasing counter
        flag(i) = true;
    end
end

%# filter ellipses to only those that made through the overlap test
num = sum(flag);
centers = centers(flag,:);
radii = radii(flag,:);
angles = angles(flag);
ex = ex(flag);
ey = ey(flag);

%# rasterized voroni diagram of the ellipses [Jonas]
E = (L ~= 0);                             %# ellipses as binary image
WS = watershed( bwdist(E) );              %# distance transform + watershed
WS = (WS == 0);                           %# WS==0 corresponds voronoi diagram
WS = bwmorph(WS, 'thicken',1);            %# thicken the lines

%# set pixels corresponding to voronoi diagram to white
II = I;
II = imoverlay(II, WS, [1 1 1]);          %# you can customize the color here

%# set pixels corresponding to ellipses using specified colors
clr = hsv(num);                           %# color of each ellipse
for i=1:num
    mask = bwperim(L==i,8);               %# get perimeter of the ellipse mask
    mask = bwmorph(mask, 'thicken',1);    %# thicken the ellipse perimeter
    II = imoverlay(II, mask, clr(i,:));   %# set those pixels with RGB color
end

%# show final rasterized image (image + ellipses + voronoi diagram)
figure, imshow(II, 'InitialMagnification',100, 'Border','tight')

截屏

于 2011-10-28T06:00:16.540 回答
0

我不知道这里的“省略号”是什么意思。但是 Stephan Fortune / Shane O'Sullivan 在 C++ 中实现了 voronoi 图,

http://www.skynet.ie/~sos/mapviewer/voronoi.php

于 2011-10-24T09:17:52.153 回答