This script generates photo mosaics with Python3 using the OpenCV library to handle images. The script requires a target image and different images to be processed as the block units in the mosaic.
Run the following command:
python mosaic.py <target> <images> <block_size>
target
: the target image directory.images
: the image directory to be used. A recursive search is used to find all the supported files. To add other image formats, edit the code to add the format prefix to the global variable IMAGE_FILE_FORMATS.block_size
: the size of a mosaic square block (in pixels).
Using a custom dataset of images placed in /data/images:
python mosaic.py data/cat.jpg data/images 20
Original image (data/cat.jpg) | Mosaic output (data/out/mosaic-20-2320x3480) |
The quality of the ouput is heavily dependent on the size and variety of your dataset.