Keilan / pyointillism

Uses a genetic algorithm to produce dot art that gets better over time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pyointillism

Pyointillism is a python script that takes an image and uses a genetic algorithm to evolve a closer and closer representation of it over time. We start with a random collection of dots in random locations, and all of the children slightly change some of these dots. We then compare the image drawn from these dots to the original, and the one with the smallest difference survives. It is named after pointillism, the art style of drawing images using only dots, as the result ends up looking similar to a painting in that style.

Initially basic shapes appear, but nothing discernable. These are the best performing organisms at generations 100,200,300,400, and 500. By the end you may be able to guess at the image.

In images 1000, 2500, 5000, 7500, and 10000, things become much clearer.

Finally at 20000,30000, and 40000, we flesh out some of the details. The original reference image is shown at the end - my fitness function shows that the 40000th generation and the reference image differ by 4.49%.

Running Pyointillism

The code is stored in a single python script. Download pyointillism.py, and install the dependencies (pil and numpy) using pip. The script will run from the beginning with no arguments, but it expects to find a file named "reference.png" in the same directory that it is running from. It will then create a results/ folder, and output the best performing image every 100 generations, along with a save file to restart from that point (start from where you left off by passing it in with the -s argument).

python pyointillism.py [-t threads] [-s save file]
-t                               number of threads to use for processing (defaults to all but 1)
-s                               location of save file to start from

Purpose

Obviously anything produced by this algorithm can be done more quickly and easily with some image manipulation magic. This was created as sort of a simple genetic algorithm example - the code is well commented with general genetic algorithm information and I hope someone can learn something from it (or show me some things I need to learn).

About

Uses a genetic algorithm to produce dot art that gets better over time

License:MIT License


Languages

Language:Python 100.0%