Skip to content

Instantly share code, notes, and snippets.

@hayd
Last active August 29, 2015 14:08
Show Gist options
  • Save hayd/27f878559b6a738544f4 to your computer and use it in GitHub Desktop.
Save hayd/27f878559b6a738544f4 to your computer and use it in GitHub Desktop.
Delaunay Tessellation from_image
import VoronoiDelaunay: Point2D, DelaunayTessellation, push!
# Create DelaunayTessellation with n points from an image
function from_image(img, n)
# placing points in places that represent the image
pts = Point2D[]
for i in 1:n
x = rand()
y = rand()
if img[int64(floor(x*size(img)[1]))+1,int64(floor(y*size(img)[2]))+1].c.b > 0.5
if rand() < 0.100
push!(pts, Point2D(1.0+rand(),1.0+rand()))
end
continue
end
x /= 2
y /= 2
push!(pts, Point2D(1.0+x+0.3,2.0-y*2/3-0.3))
end
tess = DelaunayTessellation(n)
push!(tess, pts)
tess
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment