Last active
August 29, 2015 14:08
-
-
Save hayd/27f878559b6a738544f4 to your computer and use it in GitHub Desktop.
Delaunay Tessellation from_image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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