Visualize Tiff File using Matplotlib and GDAL in Python
The file format TIFF is utilized for the storage of images that are rasterized. A library named GDAL Geospatial Data Abstraction Library is specifically designed to read these raster files, as well as other file formats, such as vector formats. The gdal library is part of the Open-Source Geospatial Foundation.
To install required modules, we can use following commands in our terminal:
We require matplotlib and GDAL modules within Python to display a tiff image.
To explain this tutorial, we will be using the following image in tiff format:
Step 1: Importing the modules and opening the file.
Step 2: Counting the total number of bands.
Step 3: Fetching the bands
We utilize the GDAL's GetRasterBand(int) to get the bands. It is important to note that the value that we pass will always begin with one (indexing of bands starts at 1)
Step 4: Reading the bands as NumPy arrays.
GDAL offers the ReadAsArray() method to convert those bands in NumPy arrays and returns the arrays.
Step 5: Plotting the arrays using imshow() function of matplotlib.
For plotting the three arrays, we'll stack them up in order.
In this tutorial, we have discussed how we can visualize tiff file format images by using matplotlib and glad modules in Python.
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week