Shapevolve¶
A genetic algorithm to recreate artworks using simple shapes, with Python 3.
Evan Zheng, July 2020.
Initially designed on Google Colab with Jupyter Notebooks. Module built with assistance from PyCharm.
View on PyPI.
Sample results:¶
The Starry Night:
Mona Lisa:
Girl with a Pearl Earring:
The Great Wave off Kanagawa:
How to install and use:¶
Standalone executable: (Windows)¶
Head over to releases and download the latest executable, shapevolve.exe
.
In the command line:
Change the directory using cd
to where the executable is located.
Then, run shapevolve.exe path/to/image_file.png
to run the program with an image as input.
You can also run shapevolve.exe -h
to view additional options.
Module:¶
Install shapevolve from PyPI using the following command:
pip install shapevolve
Here is some sample code to demonstrate how to use the module.
from shapevolve.evolver import Evolver
from PIL import Image
evolver = Evolver(Image.open("path/to/image.png")) # Sets up the Evolver object.
genome = evolver.evolve() # Evolves the genome.
image = genome.render_scaled_image() # Gets a numpy array that represents the evolved image.
genome.save_genome("path/to/save_checkpoint.pkl") # Saves the genome for later use.
More sample code can be found in samples.py
, here.
Here is a detailed API reference.
Libraries and APIs used:¶
Third-party libraries used:¶
NumPy for numerical computation with matrices
ColorThief for grabbing color palettes from images
Scikit-Image for computing image simularity
OpenCV for building images from circles
Pillow for image preprocessing
Matplotlib for image display
PyInstaller for building an executable file.
Thanks:¶
Ahmed Khalf’s Circle-Evolution module provided a great deal of inspiration.
More information¶
- shapevolve package
- Submodules
- shapevolve.adjusters module
- shapevolve.callbacks module
- shapevolve.drawers module
- shapevolve.error_metrics module
- shapevolve.evolver module
- shapevolve.gene module
- shapevolve.genome module
- shapevolve.main module
- shapevolve.mutations module
- shapevolve.preprocessors module
- shapevolve.samples module
- shapevolve.utils module
- Module contents