Creative Image Interpreter
Evolutionary algorithm for creative image reconstruction. The algorithm recreates images in a non-photorealistic style by evolving semi-transparent polygons that approximate the original image while preserving recognizable structure.
The focus of this project is not exact pixel reproduction, but controlled abstraction using evolutionary optimization.
Overview
An input image of size 512x512 is first resized and then partitioned into multiple Voronoi regions. Each region is evolved independently using an evolutionary algorithm and processed in parallel. After evolution finishes, all regions are merged into a single final image.
This design improves scalability and ensures the algorithm finishes within strict time limits.
Image Representation
Each individual represents a single image region using a fixed set of polygons. Each polygon consists of 3 to 6 vertices and an RGBA color with transparency. Polygon colors are sampled from single pixels of the target image with random variation, which preserves the global color palette while introducing artistic noise.
Evolutionary Process
For every Voronoi region, a population of candidate solutions is evolved. Fitness is computed using Mean Squared Error between the rendered region and the target region. Tournament selection is used to choose parents, crossover combines polygon sets from two individuals, and multiple mutation operators modify polygon geometry and color. The best individuals are preserved across generations using elitism. Evolution stops when a time limit or generation limit is reached.
Requirements
The project requires Python version 3.8 or newer. It uses NumPy for numerical operations, Pillow for image processing, and Matplotlib for plotting fitness curves.
Dependencies can be installed with the following command.
pip install numpy pillow matplotlib
Usage
The algorithm is executed from the command line. The first argument is the input image path and the second argument is the output file prefix.
python EA.py input_image.jpg output_prefix
During execution, the program generates reconstructed images and fitness plots.
Output
Each run produces a reconstructed image and a fitness plot showing the evolution of average and best fitness values across generations. Due to the stochastic nature of evolutionary algorithms, different runs produce different visual interpretations of the same input image.
Papers used as inspiration:
- S. Charmot — "Genetic Algorithm for Image Recreation" (Medium, 2020). Available: https://medium.com/@sebastian.charmot/genetic-algorithm-for-image-recreation-4ca546454aaa
- "Reproducing Images Using a Genetic Algorithm with Python" — Heartbeat by Comet.ml (2019). Available: https://heartbeat.comet.ml/reproducing-images-using-a-genetic-algorithm-with-python-91fc701ff84