g Orbach

download g Orbach

of 7

Transcript of g Orbach

  • 7/30/2019 g Orbach

    1/7

    Image Stained Glass using Voronoi Diagrams

    Michael Gorbach

    [email protected]

    Abstract

    The geometrical concept of the Voronoidiagram was used to create an imagefilter providing a stained glass or mo-saic effect on an image. The Voronoidiagram was calculated by exploitingits dual relationship with the Delaunaytriangulation, which was in turn calcu-

    lated using a randomized incrementalalgorithm and stored in a DCEL. Var-ious methods were tried for selectingthe points, including sampling from adistribution built using edge detection.Sampling using edge detection distri-butions was shown to provide resultssignificantly better than uniform ran-dom sampling.

    1 Introduction

    Voronoi diagrams, when calculated on someset of N points in the 2d plane, segment thespace into regions surrounding every point. Thepolygonal regions are such that, within a regionsurrounding some point p0, the point p0 is closerto any point p in that region than any other ofthe N points included in the Voronoi diagram.The mapping between points in the plane andsurrounding regions is one to one.

    This information has many uses, but one ofthe most obvious is processing an image for anartistic effect. The representation created byshading a Voronoi diagram on N points in theimage plane with colors from each sample pointcreates a stained glass or mosaic version of theimage. One of the key problems here is effectiveselection of the point set P for the Voronoi dia-gram.

    2 Theory

    2.1 Voronoi Diagrams

    First, it is appropriate to examine the algo-rithms involved in the efficient calculation of aVoronoi diagram on a set ofN points. The goalis a polygonal map of the plane consisting of aset of polygons surrounding the N points. Thepolygon surrounding a point p covers the areafor which p is the closest of the N points.

    Given two points p and p, we can create aVoronoi diagram by drawing a line perpendic-ular to the line pp, intersecting pp at its mid-point. A Voronoi diagram with more points in-cludes many such lines, meaning that each poly-gon has straight edges consisting of line seg-ments which are sections of such perpendiculars.

    Voronoi diagrams can be calculated directly,using for example the beach line algorithm fromthe work (Fortune, 1986). It is often simpler,however, to take advantage of the close rela-

    tionship that exists between the structure of theVoronoi diagram, and that of the Delaunay tri-angulation. (Guibas et al., 1990)

    2.2 Delaunay Triangulation

    A triangulation of some point set P is a planarsubdivision such that every polygon is a triangle(except for the unbounded face), and the ver-tices are points in P. A triangulation exists forevery point set P, as any bounded face can besplit up into triangles, and the unbounded face

    is simply the complement of the convex hull forP. There are, of course, many different trian-gulations on any one set of points P. Giventwo triangles bordered by a common edge, it isalways possible to flip this edge such that itconnects the remaining two points, assuming thequadrilateral in question is convex. (Berg, 2000)

    In a triangulation, it is undesirable to havesmall (sharp) angles. There is one triangula-

  • 7/30/2019 g Orbach

    2/7

    tion, called the Delaunay triangulation, whichmaximizes the minimum angle and therefore isthe best triangulation. One simple way to findthis triangulation is to take an arbitrary trian-gulation and flip all illegal edges. Here, an il-

    legal edge is defined as an edge for which flip-ping will improve the triangulation: the orderedset of angles after flipping will be lexicographi-cally greater than the set before flipping. (Berg,2000) Of course, an edge can only be flipped inthe case of a convex quadralateral. An exampleof such an edge flip is shown on fig. 1.

    It is not necessary to calculate all the anglesto determine the legality of an edge. Considertwo triangles abc and dbc that share an edge cb.Let C be the circle defined by abc. The edge ijis illegal if an only if the point d lines inside C.A proof can be found in (Berg, 2000).

    Figure 1: An edge flip during the process of

    creating a Delaunay triangulation.http://www.cescg.org/CESCG-2004/web/Domiter-Vid/

    A Delaunay triangulation can be constructedusing an incremental algorithm based on theabove. (Berg, 2000) Randomizing the point setP, add the points sequentially to the triangula-tion. Each time a point is added, start by trian-gulating the face containing the new point, andthen legalize edges recursively until all edges in

    the triangulation are legal. Thus, the algorithmmaintains a correct Delaunay triangulation ofthe currently included points as an invariant.

    2.3 Dual Transformation

    The last step in constructing a Voronoi diagramon P is to convert the Delaunay triangulationon P into a Voronoi diagram. The structuresare related through duality.

    A face in the Delaunay triangulation corre-sponds to a vertex of the Voronoi diagram, suchthat the location of the Voronoi vertex is thecenter of circumcircle for the (triangular) De-launay face. A vertex in the Delaunay trian-

    gulation corresponds to a face in the Voronoidiagram. This Voronoi face surrounds the De-launay vertex and represents the Voronoi cell forthis vertex. An edge in the Delaunay triangula-tion corresponds to a perpendicular edge in theVoronoi diagram. Two Voronoi vertices are con-nected if an only if the corresponding Delaunayfaces are adjacent. Figure 2 shows a Delaunaytriangulation and the corresponding Voronoi di-agram.

    2.4 Point Sampling

    One of the primary difficulties in using Voronoidiagrams to create stained glass effects is theselection of the point set P on which to buildthe diagram. Badly chosen points create a re-sult that captures none of the features in theoriginal image. In this project, the implemen-tation of fully automated, intelligent point se-lection was a key goal. Point selection can bedone, or adjusted, manually, however the needfor such intervention limits to applicability ofthe processing, and so was not studied here.

    2.4.1 Naive Approaches

    The simplest method for point selection usesa random sample ofN points, distributed uni-formly within the boundaries of the image. Sucha method is of course very simple to implement,and also has an advantage that follows from itsuniformity. Because the distribution is uniform,the sizes of all the Voronoi cells will be relativelysmall, and thus a badly-colored Voronoi cell canhave only a limited size. The obvious issue with

    such a method is that it fails to account for theglobal features of an image. Random point se-lection, in practice, results in significantly dis-torted representations, especially in high-detailregions of the image, even at large N.

    A grid-based point selection approach is an-other simple alternative. It has the advantage ofhighly uniform cell size, similar to that seen in areal mosaic. Like uniform random sampling, it

  • 7/30/2019 g Orbach

    3/7

    Figure 2: Example of a Delaunay triangulation(top) and corresponding Voronoi diagram (bot-tom). The colors have no meaning.

    suffers from a failure to account for the imagesimportant features. Good representations canonly be obtained with fairly large N values.

    2.4.2 Distribution Sampling

    The earlier discussion of uniform sampling canbe generalized to an arbitrary probability distri-bution on the 2d plane of the image. The ques-tion, then, is what distribution Ps(x, y) on theimage pixels would, when sampled from for atotal ofN points, produce the best representa-tion of the image. One quantitative criterionfor Ps(x, y) is the error between the colored,N-point Voronoi representation with samplingfrom Ps(x, y) and the real image. Such a value,however, does not necessarily reflect an aestheticjudgment of the colored Voronoi mosaic.

    Edge detection appears as an efficient way toobtain a good Ps(x, y). Good mosaics are cre-ated when Voronoi cell edges fall on edges ofthe image. In order for this to happen, Voronoipoints must be located at equal distances froman edge line. It is undesirable for sampled pointsto fall on image edges themselves, as then theVoronoi cell surrounding that point is likely tobe badly colored, in a way that is not expressiveof key image features. The goal then, is to re-ceive a distribution that has symmetric and sig-

    nificant values around edges (leading to pointslikely sampled there), and low values directly onedges. Here, symmetric means that values areequal at equal distances along a perpendicularto the edge.

    Such a distribution can be achieved usingbasic edge detection and blur filters. Specifi-cally, it is effective to use a distribution of theform Ps(x, y) = Pblur(x, y) Psharp(x, y). Here,Psharp(x, y) comes from an sharp, or only veryslightly blurred, black and white edge detection

    image. Pblur(x, y) comes from an image pro-cessed with the same edge detection filter, fol-lowed by a significant (on the order of 5 pix-els) gaussian blur. The subtracted distributionhas low (dark) values immediately on the edges,and higher (lighter) values farther out from theedges. Due to the Gaussian blur, the lighter val-ues decrease in intensity with distance from theedge. Example distributions are presented on

  • 7/30/2019 g Orbach

    4/7

    fig. 3. Note that the distribution along bothsides of an edge is symmetric, which is good forVoronoi point selection.

    2.4.3 Related Work

    In addition to considering the distributionPs(x, y), it is also possible to look instead at therepresentation error discussed earlier. This wasimplemented in the work (Dobashi et al., 2002).The authors started with a simple set of pointsleading to a hexagonal Voronoi diagram acrossthe image. They then adjust the locations ofthe Voronoi points to decrease the error (calcu-lated as difference in colors per pixel) betweenthe mosaic and real image representation. In thefirst phase, the entire set of points is moved inbatch, with each point moving somewhere in its

    surrounding 8 pixels in such a way as to decreasethe error. This process continues until changesin error are below a threshold. The second phaseimplements finer adjustment where each site ismoved individually within its 8 pixels and theerror is recalculated each time.

    While this approach appears to be effective,it requires significant computational power evenwith approximations, and the inclusion of man-ual adjustments in the paper makes it difficultto judge the effectiveness of such a method for

    purely autoamted processing.

    3 Methodology and Implementation

    3.1 The Doubly-Connected Edge List

    The most important component in an implemen-tation of the above algorithms is the data struc-ture used to represent the planar subdivision,whether it be the Delaunay triangulation or theVoronoi diagram. This data structure must sup-port several operations in a performant way. It

    needs to allow fast adding of points into an exist-ing triangulation structure, flipping of any par-ticular edge, and traversal of a face to find itsboundary edges.

    The most common data structure used tomeet the above requirements is called a dou-bly connected edge list (DCEL) (Muller andPreparata, 1977). The structure contains sev-eral types of records: faces, edges, and vertices.

    Figure 3: Examples of sampling distributionscreated using edge detection: Psharp(x, y) (top),Pblur(x, y) (middle), and Ps(x, y) (bottom).Edge detection and blur were implemented us-ing Apple Inc.s Core Image processing filters.

  • 7/30/2019 g Orbach

    5/7

    Edges are represented as half edges, storing apointer to their twin, adjacent face, and dou-bly linked list pointers allowing traversal of faceboundaries. A face record simply contains apointer to one half-edge along the faces outer

    boundary (if it exists), and a set containing oneedge along every hole inside the face. TheDelaunay triangulation was constructed in aDCEL, and then the Delaunay DCEL was trans-formed into its dual, representing the Voronoidiagram.

    The DCEL structure described here meets allthe requirements for storing a planar subdivi-sion. However, given a point, the structure doesnot provide a fast way to locate the face con-taining a point. For this purpose, an additionalDAG (Directed Acyclic Graph) data structure

    is layered on top of the DCEL.

    3.2 DAG For Point Location

    A Directed Acyclic Graph was constructed toprovide fast point location during triangulation.This point location was used during the first tri-angulation step, where it is necessary to findthe face containing the point being added. TheDAG algorithm used was described in (Berg,2000).

    The leaf nodes of the DAG correspond to the

    current triangulation. The other nodes corre-spond to previous triangles that existed ear-lier during the incremental triangulation pro-cess. When a point p is added, causing a splitof the face f, the leaf node representing f re-ceives 3 children for the newly created triangles.The DAG is also updated on edge flips, leadingto situations where a leaf node has more than 1pointer leading to it.

    Using such a DAG structure, a point can belocated by starting from the root and navigating

    down the children, checking for containment inthe process.

    4 Results and Discussion

    The figures below present the results of con-structing mosaic representations for a test im-age.

    The butterfly image was chosen as it is sim-ilar to example images used in (Dobashi et al.,

    2002). It is extremely difficult to constructed au-tomated mosaic representations on images withmany human faces.

    Looking at the images on figs 4 and 5, we cansee that the representation unsurprisingly im-

    proves with increasing N. It is clear that theimages generated using edge-detection distribu-tion based sampling retain significantly more ofthe key features, and also have a far cleanerappearance. This is due to points being sam-pled from a distribution symmetric around theedges, leading to Voronoi cell edges matching upwith image edges. The improvement using edge-detection distribution based sampling is partic-ularly evident with lower N values.

    Significant artifacts still exist with edge-detection based sampling under lower pointcounts. This is because the correct distributiondoes not guarantee a good set of sampled pointswith low N, meaning that there are or empty ar-eas in the points. One approach to remedy thiswould be to adjust the distribution during thesampling process, subtracting discreet, 2d Gaus-sians from the distribution around each point asit is sampled. This would help prevent clustersof points and empty areas, improving uniformitywith low N.

    Ideally, it would be effective to add equidis-

    tant points in pairs, one on each side of an edge.Doing this, however, requires knowledge of theedges as vector paths instead of as lighter pix-els in an image. Such an approach would notrequire sampling, and would probably work sig-nificantly better than a distribution-based ap-proach. It does, however, require a very differentkind of processing.

    5 Conclusion

    A stained glass / mosaic filter was successfullyimplemented based on Voronoi diagrams. Sev-eral solutions to the problem of sampling pointswere compared. While the solution by (Dobashiet al., 2002) provides good results, it requiresboth significant processing power and manualadjustment. A simple, fully automated sam-pling method was proposed based on subtractionof blurred distributions obtained using edge de-

  • 7/30/2019 g Orbach

    6/7

    Figure 4: An example image (top), rendered us-

    ing distribution-based point selection. The dis-tribution was created by subtracting two blurrededge detection distributions, with a blur of 5.0and a blur of 1.0. The middle image has N =1000 points sampled, and the lower image hasN = 5000.

    Figure 5: An example image (top), rendered us-ing uniformly random point selection. The mid-dle image has N= 1000 points sampled, and thelower image has N = 5000.

  • 7/30/2019 g Orbach

    7/7

    tection. Results presented from application ofthis method, shown on figs. 4 and 5, are bothsignificantly cleaner than the mosaics createdusing random sampling, and more reflective ofkey image features.

    References

    Mark de Berg. 2000. Computational geometry: al-gorithms and applications. Springer, Berlin, 2ndrev. ed edition.

    Y. Dobashi, T. Haga, H. Johan, and T. Nishita.2002. A method for creating mosaic images us-ing voronoi diagrams. In Proc. EUROGRAPHICS2002 Short Presentations, pages 341348.

    S Fortune. 1986. A sweepline algorithm for voronoidiagrams. In SCG 86: Proceedings of the sec-

    ond annual symposium on Computational geome-try, pages 313322, New York, NY, USA. ACM.

    Leonidas J. Guibas, Donald E. Knuth, and MichaSharir. 1990. Randomized incremental construc-tion of delaunay and voronoi diagrams. In Pro-ceedings of the seventeenth international collo-quium on Automata, languages and programming,pages 414431, New York, NY, USA. Springer-Verlag New York, Inc.

    N. E. Muller and F. P. Preparata. 1977. Finding theintersection of two convex polyhedra. TechnicalReport ADA056889, U. Illinois at Urbana Cham-

    paign, Coordinated Science Lab, October.