Photomosaic with OpenCV
This is an extremely simple software to turn your set of holiday pictures to a cool mosaic image. It was developed for fun/excercise.
Please note that all the mosaic images in this readme are reduced to a normal dimension (for quick visualization over HTTP) and therefore lose in resolution. To download a realistic mosaic image, click here. This is huge but fine for prints.
Dependencies
This code depends on two libraries:
- OpenCV for image processing purposes;
- Boost for recursive search on filesystem.
How does it work?
It performs two phases:
1 - Pixelization: it searches recursively for images in the source folder and stores each of them in the selected pixelization folder after a resize (the new dimension is customizable, square is highly recommended). These new little images will be the pixels of the final mosaic. An index is also computed pairing each image to its mean color.
2 - Mosaicization: the source image is reduced by the selected factor (for instance, 0.05) to get a low resolution version (suitable for mosaicization). Then, the mosaic image is build replacing each pixel with the pixel image having the closest mean color. Please note that image repetition in close pixel is avoided introducing a queue of recently used pixel images. You can customize the length of this queue (skip factor).
Build your own
After the environment setup and build, you can customize your mosaic changing the settings.ini configuration file. Choose properly pixel image size and source scale factor and think about what the final size will be.
Also choose the skip factor properly. It is just a workaround, so you'll probably need to struggle a little bit. Here's what happens without it:
This is clearly unacceptable, since we want the lowest pixel image repetition we can get.On the other hand, if we exaggerate, we would get something like:
Look how the software has too many prohibited images, so it has to choose between ones having mean color really different from the pixel under consideration. Since the substitution is performed from top-left to bottom-right, you can clearly see degradation and the points where the buffer empties.The right factor depends also on the total number of different pixel images. In a few minutes you'll guess it!