Home 9 The Art of Technology 9 Image Processing : Python Read Image File and Convert into an Array

There are a tons of image already – instead of going though the pain staking process of creating by hand our own images, I am going to use an image I already captured.

And yes, it is of my three cats. I am also adding to the collection of cat images on the internet.

Here is the image below – feel free to use it in any of the examples.

thecats
The Cats

The code below uses PILLOW to read in the image, and then using NUMPY we can convert it into an array. Since it is a color image it will become a 3d array with the shape of 844,600,3.

#%%
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt

# Image File we are loading
imageFile = r"D:\temp\thecats.jpg"

# Pillow Image Object
inputImage = Image.open(imageFile)

# Convert To Numpy Array
imageArray = np.array(inputImage)

# Using matplot to load the array into their image display function
plt.imshow(imageArray)

# Shows the Image
plt.show()

Color images are great – however they do require some more RAM and processing power. Up next we will take a look at various ways to convert a color image to black and white. This will greatly speed things up on lower powered devices.


See the Image Processing Table of Contents



Have a Creative or Technical Project in Mind?

Looking for guidance, insights, or a fresh perspective on your technical or creative journey? Or just somebody to chat with?


LET’S KEEP IN TOUCH!

Get notified when I post something new!

We don’t spam! Read our privacy policy for more info.


Pin It on Pinterest

Share This