Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Latest commit

 

History

History
49 lines (31 loc) · 2.31 KB

README.md

File metadata and controls

49 lines (31 loc) · 2.31 KB

Generate Mosaic Image

Alt text Fig: base image: test_image_1, desired height: 20, desired width: 10

This is a mosaic image generator written in Python. You can use a base image and a collection of images that will be used as mosaic piece.

Process

The base image is split into frames, and we iterate through them row by row. The frame dimensions are specified by the desired height and width. At the end of each row and the bottom row, the overlapping mosaic images are cropped before being stitched onto the base image.

Alt text

For each frame of the base image, the average color is calculated and blended with a random image before it is stitched into the base image.

Alt text

The final image is saved in the current directory.

How to use

You can either change the location of the base image and mosaic_images or place your images there. Then, set your desired height and width and run the program.

    base_img_path = 'resources/base_image/test_image_me.jpg'
    path_to_mosaic_image = 'resources/mosaic_images'
    desired_height = 200
    desired_width =  100

Further Development

This procedure can be used with every mosaic piece or just one, but there are other methods of creating mosaic images. Another way is to find the image that is closest to the average color of the frame and use it as the mosaic piece. This method could be added as an alternative.

Currently, all mosaic pieces are resized to the same dimensions. This means that we cannot maintain the aspect ratio of the original image. With a 2D packing algorithm, it could be possible to preserve the aspect ratio of the original image and create a different mosaic look."

Resources

Links