Very Basic Photo Collage in Python [using Numpy & Matplotlib]

Very Basic Photo Collage in Python [using Numpy & Matplotlib]

In start of 2021 - Bernie Sanders Chair Meme gets viral.

This gives me an idea - Can I use python to add my_image with Sir Bernie Sanders image ?

I though, we can do this via Matplotlib & Numpy libraries.

Because we have to arrange the images in some plot (Horizontally/Vertically)

Collage is basically a combination of photos (arranged horizontally, vertically or both)

I have downloaded some images of dogs and cartoon from Google and save it one Folder 'Images'

Screenshot from 2021-01-24 13-23-02(1).png

Using Matplotlib

Step1

First Store Images Path in some array/list.

carbon(5)(1).png

Step2

Read an Image using Open-CV and Show in a plot and finally save the output

carbon(6)(1).png

Below is the output

matplotlib_output.jpeg

Using Numpy

Numpy provides two method hstack (to stack two arrays horizontally) and vstack (to stack two arrays vertically. So we just use that.

First we read the image in some in a list. Then we read that list and arrange accordingly.

carbon(7)(1).png

Below is the output

numpy_output.jpeg

In Numpy method ==> we have hardcoded the rows/columns. But we can write the logic as well (depend on number of images in an array, it arrange accordingly) OR we can take the input form user (about number of rows and columns)