How to read an image stored in a tiff file with python ?

Published: March 03, 2023

Tags: Python; Protection Status

TIFF, or Tag Image File Format, is a digital file that securely stores raster graphics and image data.

Reading an image stored in a TIFF file with Python is a relatively straightforward process. The first step is to import the necessary libraries such as OpenCV, PIL and NumPy.

Read tiff file using PIL

from PIL import Image

import numpy as np

im ='landsat_image.tiff')


Convert the image to a matrix using numpy

imarray = np.array(im)

print( imarray.shape )


(7741, 7611)

Plot the image using matplotlib

After performing some operations such as resizing, cropping the image using python, you can visualize the image using matplotlib and convert it to other formats such as JPEGs and PNG:

import matplotlib.pyplot as plt



Links Site