12 December 2008

Genetic Algorithm with Darwin's Face: Dynamic SVG

In a previous post I described how I've implemented a genetic algorithm finding the best set of colored triangles to re-create an image. I've just changed the output of the program: it now saves the output as a dynamic SVG picture. Watch the creation of the picture here:


(yes I know, this is a colored image whereas the original image was in B&W. This is because my program automatically converted the colors of the triangles to a 8bit-gray-levels image)




The current iteration on Friday:



Pierre

5 comments:

Antonio said...

cool!
what is your criterium (objective function) for the best set of colored triangles?

Pierre Lindenbaum said...

fitness=0;
for(x -> width)
for(y->height)
fitness += abs( diffRed(x,y) )
fitness += abs( diffGreen(x,y) )
fitness += abs( diffBlue(x,y) )

return fitness

Egon Willighagen said...

With how many triangles did you start? It seems logical to increase this during the run, but likely with some penalty on the number of triangles... maybe an parabolic term for that? Not too few, not too many...

And, are the triangles transparent? I think they should be...

Morgan Langille said...

That is really cool!

Pierre Lindenbaum said...

@Egon: there is between 50 and 250 triangle in each solution (see the parameters maxTrianglePerSolution and inTrianglePerSolution in the source http://code.google.com/p/lindenb/source/browse/trunk/proj/tinytools/src/org/lindenb/tinytools/GAMonaLisa.java

And yes the triangles are transparents: see the 'alpha' field in the internal class Triangle