The Photo Mosaic Creator is a Python project that transforms an input image into a mosaic by replacing its tiles with smaller images from a predefined set. The project utilizes OpenCV and NumPy for image processing.
- Python 3.x
- OpenCV
- NumPy
-
Clone the repository
-
Install dependencies:
pip install -r requirements.txt
-
Ensure that the input image is the one present in "image.jpg" and the source tile images are in the predefined animals folder.
-
Run the Photo Mosaic Creator script:
python main.py
-
View the generated mosaic in the "output.jpg" file.
The Photo Mosaic Creator follows these steps:
-
Image Caching:
- The script reads images from the "animals" directory and calculates the average color for each image.
- The data is cached in a JSON file named "cache.json" to avoid recalculating for every run.
-
Mosaic Generation:
- The input image is divided into tiles, and each tile's average color is calculated.
- For each tile, the closest match from the cached image data is determined based on average color.
- The selected image is resized to match the tile dimensions and replaces the original tile.
-
Display and Save:
- The resulting mosaic is displayed using OpenCV.
- The final mosaic is saved as "output.jpg."
The Dataset used for tile images is the Kaggle Animal Image Dataset. Link - https://bit.ly/3G1TLWK
In the Photo Mosaic Creator project, OpenCV (cv2) is a key library for various image processing tasks:
-
Image Loading:
cv2.imread()
is used to read input images and images from the predefined set.
-
Image Resizing:
cv2.resize()
is employed to resize the selected images to match the dimensions of the tiles in the mosaic.
-
Image Display:
cv2.imshow()
is utilized to display the intermediate mosaic during the creation process.
-
Final Mosaic Save:
cv2.imwrite()
is used to save the final mosaic as "output.jpg."
OpenCV plays a crucial role in handling various image manipulation tasks, contributing to the creation of vibrant and visually appealing photo mosaics.
Adjust parameters like tile_height
, tile_width
, and others in the script to experiment with different mosaic effects.
Contributions are welcome! If you have ideas for improvements or find issues, please create an issue or submit a pull request.
This project is licensed under the MIT License.