mosaic-machine is the project which takes an image and creates a photomosaic using images from a library (tiles) to recreate the image.
A large library of images will allow for more accurate results because of a larger sample size to match each pixel colour.
An issue that was ran into when calculating the overall colour of an image was what metric to use. A natural response would be to use the average values of each pixels RGB value, which yields not so accurate results, such as the image below.
Example of average colour, Adam Spannbauer
Using average colour
Another approach would be to use the most dominant colour in an image. This uses a simple clustering algorithm called K-means clustering to find clusters in an image and use the colour palette to choose the most common cluster.
Using most dominant colour
- Python
- OpenCV
- NumPy
- SciPy
- Pillow
- pip
Optional:
- NodeJS
- bulksplash
First, clone the repository:
git clone https://github.com/nehemiah-negussie/mosaic-machine.git
Second, install all libraries, languages and tools shown above.
Third, edit the core.py
and setup.py
file to your specific path to the library and image paths.
Fourth, run the setup.py
file using python3 setup.py
to create a values.txt file that will be vital in the running of the program.
Fifth, go to the Usage section to run!
If you want to have a large library I recommend using the bulksplash tool. You should export the artists to a JSON file so you can credit them, according to Unsplash's TOS.
python3 core.py [output file]
Sample:
python3 core.py awesome_landscape_mosaic.png
The program will run and ask you what percentage of the original image to choose. A lower percentage will run significantly faster than higher percentages but will be more granular.
After the program is finished running, it will ask if the user would like to download the image then show the image finally.
GNU GENERAL PUBLIC LICENSE
All Unsplash artists that are used in my library are credited in the bulksplash-credits.json
file.