top of page

Analysis of Normalized Difference Vegetation Index (NDVI) using Google Earth Engine (GEE)

What is NDVI?

In simple terms, Normalized Difference Vegetation Index (NDVI) describes the vegetation by measuring the difference between near-infrared (which vegetation strongly reflects) and visible or red light (which vegetation absorbs).

Background study of NDVI

When sunlight strikes the objects, certain wavelengths of this spectrum are absorbed and reflect others. Chlorophyll, the pigment in plant leaves strongly absorbs visible light (from 0.4 to 0.7 µm) for the process of photosynthesis. On the other hand, the cell structure of the leaves strongly reflects near-infrared light (from 0.7 to 1.1 µm). In general, if there is much more reflected radiation in near-infrared wavelengths than in visible wavelengths, then the vegetation in that pixel is likely to be dense and may contain some type of forest. If there is very little difference in the intensity of visible and near-infrared wavelengths reflected, then the vegetation is probably sparse and may consist of grassland, tundra, or desert.

How to calculate NDVI?

The formula to calculate the NDVI is: NDVI = (NIR — VIS)/(NIR + VIS)

The formula of NDVI is the ratio of difference of the near infrared and visible or red light divided by the sum of near infrared and visible or red light. The calculation of NDVI for a given pixel always result in a number that ranges from -1 to +1. The index became "normalized" in 1973 when a group of scientists from the Texas A&M University began to calculate not the ratio of infrared light to red, but the ratio of their difference to a total — this is actually the modern formula. If the calculations leads to zero - it depicts no vegetation and if the value tends to +1, it indicates dense vegetation. However, in any case if the values leads to negative (say -1) - it depicts that there is water bodies.

From the figure attached above, we can see the green or healthy vegetation (left image) which is reflecting 50% of near infrared light & absorbing 8% of the red light. The Unhealthy or sparse vegetation (right image) reflects 40% of near infrared light and 30% of red light. The calculated values of NDVI for the left and right images are 0.72 and 0.14 respectively.

Calculation of NDVI using Google Earth Engine (GEE)

Here we will do the analysis for the development of the Normalized Difference Vegetation Index (NDVI) for a particular region using GEE for the desired duration. Google Earth Engine is a cloud computing platform that can extract parameters from satellite images. It provides an interactive platform for geospatial algorithm development at scale & making substantive progress on global challenges that involve large geospatial datasets. The GEE can then visualize the data, plot it in time series graphs, and data can be downloaded for external processing.

Now, let's start our journey to fulfil the objective of this blog.

Here we will be using dataset of images taken from the satellites. Here the satellite is LANDSAT. Now let's understand the Spectral Band Information of Landsat. The images captured by Landsat are composed of seven different bands, each representing a different portion of the electromagnetic spectrum. The bands that we are interested here are bands 3 and 4.

  • Band 3 (0.63-0.69 μm, red): Since vegetation absorbs nearly all red light (it is sometimes called the chlorophyll absorption band) this band can be useful for distinguishing between vegetation and soil and in monitoring vegetation health.

Fig: Image showing Band 3 (red/visible light)

  • Band 4 (0.76-0.90 μm, near infrared): Since water absorbs nearly all light at this wavelength water bodies appear very dark. This contrasts with bright reflectance for soil and vegetation so it is a good band for defining the water/land interface.

Fig: Image showing Band 4 (near infrared light)

We followed the steps as mentioned below before starting to write the code.

1) Open Google Earth Engine & sign up to open the code editor (after getting access)

2) In order to write the script, go to 'Scripts' and click on 'New' and then tap on file. Give a name to your file and press Enter

3) Click on the new file that you created and start writing the code in JavaScript.

Several documentations can be referred there to get a better understanding of Google Earth Engine

Gist of the Script

Here we are able to see the Map at the bottom. At right hand side of the panel, we see three divisions namely Inspector, Console and Tasks. Whenever we tap on a particular location in the map - the latitude as well as the longitude is being shown in the 'Inspector'. The same is being noted and used in the code for the region of interest. The 'Console' shows the output when the script is being compiled, whereas 'Tasks' gives information for any tasks due in the platform.

The Dataset used here has 7 bands and we are interested in Band 3 and Band 4.

Now, we start writing the code in the code editor. The coordinates for the latitude and longitude for our objective is shown in line no. 1 in the code. ee.Geometry.Point will take the given coordinates as a point in the map. A layer will be created when Map.addLayer() is being executed.

We have taken certain dates of interest here which means a particular duration is being considered to visualize the output. The images taken from the satellites contains both clear as well as unclear images depending on several situations. Hence, we have considered the images that are not being covered by cloud here. After sorting and filtering out the best images from the dataset.

Here in this code, we have extracted the size of the image set without the cloud cover, subsequently we have showcased the best image that has no cloud cover. The date and the name of satellite that has captured the best image is also being printed here.

The complete code is being shown below.

//input coordinates
var city=ee.Geometry.Point(-103.72307427003409,38.74603976510611);


//dates of interest
var start =ee.Date('2008-08-01');
var finish=ee.Date('2009-08-01');

//image collection
var collectimage=ee.ImageCollection("LANDSAT/LE07/C01/T1_SR")

//size of the image
var count=collectimage.size();
print('The size is of the images without cloud cover is', count);

//sort the images with best output
var best=ee.Image(collectimage.sort('CLOUD_COVER').first());
print('The best image without cloud cover is',best);

//date of the image acquisition
var date=best.get('SENSING_TIME');
print('The date on which it was captured',date);

//name of the satellite
var name1=best.get('SATELLITE');
print('The name of the satellite is:',name1);


var'B4'); //band 4 representing red light that vegetation absorbs
var'B5'); //band 5 representing near infrared that vegetation reflects

//formula of nvdi calculation
var nvdi=band_nir.subtract(band_red).divide(band_nir.add(band_red));

//nvdi stats
var nvdi_stats = {
 min: -1.0,
 max: 1.0,
 palette: [
 '05450a', '086a10', '54a708', '78d203', '009900', 'c6b044', 'dcd159',
 'dade48', 'fbff13', 'b6ff05', '27ff87', 'c24f44', 'a5a5a5', 'ff6d4c',
 '69fff8', 'f9ffa4', '1c0dff'

Map.addLayer(nvdi, nvdi_stats, 'NVDI');

The calculation of NDVI is being performed in the second half of the code where the bands are selected from the best image that was sorted in the first half. We have written the formula and then the minimum and maximum values with the respective colors in the palette is attached to distinguish different regions or patterns in a region.

You can execute the code from the link below for the real time analysis and visualization.


The console is as shown post execution of the code. Here we are able to see statements which is required to be printed from the code. As seen from the output, there are 42 images without cloud cover and the best of the 42 images was being captured on 12th August 2008.

As we can see the circles in the figure below, the dark circles represents the maximum value or +1 whereas minimum value or -1 values are being shown by the lightest circles representing dense and sparse vegetations respectively. Some circles shows color that are between dark and light - these can be termed with values between +1 and -1 representing medium range of vegetation in the given duration.


NDVI is the most popular and widespread one, and it also has one important advantage: the high resolution of images with data from the satellite. It is important to understand that the NDVI is an indicator of the plant's health but it says nothing about the cause of a particular condition. One of the drawbacks of the NDVI is that if a plant develops very actively, it becomes impossible to distinguish an abnormally green plant from a "normally" green one. The NDVI index also depends on the weather: if clouds are overhanging a field for a long time, the satellite image will be unclear. Here GEE plays a significant role in analyzing the vegetation via NDVI in the regions with the help of the required datasets. NDVI can further be used to determine the precision farming model etc.

Excerpts added from:



Please give your valuable feedback in the comments. Drop a like if you really enjoyed this blog. Connect with me on LinkedIn
85 views0 comments

Recent Posts

See All
bottom of page