You are currently viewing How to Read and Show Image using Pillow

How to Read and Show Image using Pillow

The Python Imaging Library (PIL) is one of the most popular libraries for opening, manipulating, and saving images. PIL makes it easy to read and write images in a wide variety of formats, including JPG, PNG, GIF, and BMP. We’ll take a look at the way you can read and show image using Pillow.

The Python Imaging Library (PIL) is one of the most popular libraries for opening, manipulating, and saving images. PIL makes it easy to read and write images in a wide variety of formats, including JPG, PNG, GIF, and BMP. We’ll take a look at the way you can read and show image using Pillow.

Install PIL in Python

You can install pillow python library using PIP.

pip install Pillow

Show Image using Pillow Code:

from PIL import Image
img_pillow = Image.open('/content/solar.jpeg')
print(img_pillow)

The pillow library will not show you the array of image as an output like other libraries. But it will directly show the image.

Output:

<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=600x375 at 0x7F71F5166990>

If you want to convert the pillow image into NumPy array, then follow the below code.

Pillow image to NumPy Conversion Code:

import numpy as np
image_Array = np.array(img_pillow)
print(image_Array)

Output:

[[[25 14 30]
  [28 17 33]
  [32 19 36]
  ...
  [18 16 40]
  [18 12 40]
  [20  9 39]]

 ...

 [[ 4  4  4]
  [ 4  4  4]
  [ 4  4  4]
  ...
  [ 4  4  4]
  [ 4  4  4]
  [ 4  4  4]]]

Other Python Libraries to Read Images:

How to Read and Show Image using OpenCV

How to Read and Show Image using Skimage

How to Read and Show Image using Matplotlib

How to Read and Show Image using Imageio

Leave a Reply