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


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 = Image.open('landsat_image.tiff')

print(type(im))

Convert the image to a matrix using numpy

imarray = np.array(im)

print( imarray.shape )

output

(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

plt.imshow(imarray)

plt.show()

References

Links Site
pillow pillow.readthedocs.io