Evolutionary Algorithm: Image-Forming Polygons

My co-worker recently showed me a neat project that he found online: http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/

The basic idea is that an evolutionary algorithm is used to mutate a set of polygons until they resemble a target image.

I immediately wanted to try implementing this idea on my own.  I used Python and PIL (Python Imaging Library).  After tweaking it for a couple weeks, I had quite satisfactory results.  Here’s a sample, a picture of me:

Me, in the form of 362 polygons.

Me, in the form of 362 polygons.

It took 17 hours of running the program to reach this level of resemblance, although decent results only took 10 or so minutes.  Since then, I’ve improved the program even more and it’s much faster.  My latest implementation uses Pyglet, an OpenGL based library.

I think I’ve scratched this itch, but I did discover some neat Python libraries along the way and I’m excited to play with them some more.  Pyglet, Rabbyt and Pymunk are some of the things I’ve just recently discovered in working on this (though only Pyglet is directly related).

This entry was posted in Programming. Bookmark the permalink.

One Response to Evolutionary Algorithm: Image-Forming Polygons

  1. Any chance you will make the code available? A few months ago, I tried with PIL as well and found it was not terribly fast. I’d be really interested to see your pyglet based code.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">