Be Coded….


NDVI Image Processing

NDVI Image Processing Using Python:

Normalized Difference Vegetation Index (NDVI)

To determine the density of green on a patch of land, researchers must observe the distinct colors (wavelengths) of visible and near-infrared sunlight reflected by the plants. As can be seen through a prism, many different wavelengths make up the spectrum of sunlight. When sunlight strikes objects, certain wavelengths of this spectrum are absorbed and other wavelengths are reflected. The pigment in plant leaves, chlorophyll, strongly absorbs visible light (from 0.4 to 0.7 µm) for use in photosynthesis. The cell structure of the leaves, on the other hand, strongly reflects near-infrared light (from 0.7 to 1.1 µm). The more leaves a plant has, the more these wavelengths of light are affected, respectively.

By taking the ratio of red and near infrared bands from a remotely-sensed image, an index of vegetation “greenness” can be defined. The Normalized Difference Vegetation Index (NDVI) is probably the most common of these ratio indices for vegetation. NDVI is calculated on a per-pixel basis as the normalized difference between the red and near infrared bands from an image:

where NIR is the near infrared band value for a cell and RED is the red band value for the cell. NDVI can be calculated for any image that has a red and a near infrared band. The biophysical interpretation of NDVI is the fraction of absorbed photosynthetically active radiation.

Many factors affect NDVI values like plant photosynthetic activity, total plant cover, biomass, plant and soil moisture, and plant stress. Because of this, NDVI is correlated with many ecosystem attributes that are of interest to researchers and managers (e.g., net primary productivity, canopy cover, bare ground cover). Also, because it is a ratio of two bands, NDVI helps compensate for differences both in illumination within an image due to slope and aspect, and differences between images due things like time of day or season when the images were acquired. Thus, vegetation indices like NDVI make it possible to compare images over time to look for ecologically significant changes.


The output of NDVI is a new image file/layer. Values of NDVI can range from -1.0 to +1.0, but values less than zero typically do not have any ecological meaning, so the range of the index is truncated to 0.0 to +1.0. Higher values signify a larger difference between the red and near infrared radiation recorded by the sensor – a condition associated with highly photosynthetically-active vegetation. Low NDVI values mean there is little difference between the red and NIR signals. This happens when there is little photosynthetic activity, or when there is just very little NIR light reflectance (i.e., water reflects very little NIR light).

Programming in Python [Convert IR to NDVI]:

At first we need some Libraries to call in the script:-

To know about matplotlib, LinearSegment

Color Bar to indicate color bandwidth in the output:

A function performs the NDVI calculation and returns an GrayScaled frame with mapped colors)

This script use NGB (Nir, Green, Blue) i.e; NOIR image and if you wish to run this script in virtual env then follow below steps:-

Description Command
1.1 install virtualenv by executing in console “pip install virtualenv”
1.2 Go to the folder where you whant to have virtual env cd my_project_folder
1.3 Create virtualenv by virtualenv
1.4 Activate virtualenv source /<path_to_virtual_env>//bin/activate

Install requirement.txt file which contains instruction libraries with specific version

Description Command
2.1 Go to you project folder cd
2.2 Execute pip install -r requirements.txt

Script Usage of

-i, input image
-o, output path and file name by default it use ‘NDVI.jpg’
-c, colors to create colormap by default it use — ‘gray’, ‘gray’, ‘red’, ‘yellow’, ‘green’

>>> python -i image.jpg -o test.jpg
>>> python -i image.jpg -o test.jpg -c red green blue
>>> python -i image.jpg

Full source code can be downloaded for here.


Comments are Closed

Theme by Anders Norén