jlongster

Mona Lisa genetically drawn from Scheme

May 25, 2009

Remember the inspiring project which drew Mona Lisa using a genetic algorithm (or, according to some people, stochastic hill climbing)? I decided to implement this technique in Scheme. I've always been fascinated by genetic algorithms and this is a good project to learn them.

I call the project "Genetic Canvas" (github). It is written in Gambit Scheme on OS X and uses OpenGL.

I explored various methods of helping the genetic algorithm, from edge detection to color analysis. In the end, most of this work ended up hurting its ability to solve the problem. The basic process uses a population size of 10, randomly creates and mutates polygons on the screen, and analyzes each solution by summing the color difference of each pixel. We then use elitist selection to pick the best one, and rinse and repeat.

There were points in the project which I felt hatred towards genetic algorithms. I underestimated the flaky and irrational behavior of the whole process, which is something close to a temperamental child. All of your mutation rates, population sizes, mutation and fitness procedures, etc. have to be exactly right, and there's no way to provably solve which settings are correct. You have to eye the solution yourself and tweak the settings as you see fit.

In the end, I still find genetic algorithms interesting. This application of them is simply not very interesting, as it has no practical use, and the problem set is rather difficult to solve generally (large and small images, various compositions, etc.).

I wanted it to find an acceptable solution quickly. The following images were rendered in about 30 minutes.

With borders...

And finally, taking about 3 hours...

Comments are not implemented yet. In the meanwhile, send me an email.