I was recently working on a project that involved manipulating images so we could run an unsupervised machine learning algorithm on it. Being a Python fanboy, rather than going the Photoshop route, I decided to use Python and its libraries to do the manipulation for me.

In this article, I highlight how I used the Image sub module in PIL to create the images I needed for my project.

Gather images

I took two images for this article, both from Unsplash. I particularly used different sized images so we can access how different sized images might interact with one other.

Image for post

Image for post

Image by sergio souza

Note that the first image is wider while the second image is longer in height. We’ll have a lot of fun combining them.

I usually use unsplash.com as it has a humongous variety of high quality images all freely accessible. Obviously, don’t skip on giving proper credit to the artists. It’s good ethics!!

Install libraries

I am using Python 3.6 here but all versions of Python 3.5 and above should ideally work.

pip install Pillow
pip install matplotlib

The Pillow is the PIL package containing our sub module Image. I’ve also decided to install matplotlib because it just makes it easier to display images within a Jupyter notebook irrespective of the size of the image. For example, when I tried to directly display the image using Image, it opened a new window with the image all full blown up.

If you want to do this in Jupyter notebooks, install it using pip install jupyter, start the Jupyter server and create a new notebook.

#towards-data-science #data-science #deep-learning #data analysis

 Multi-Task Feature Extraction for Farming Fate Grand Order
1.20 GEEK