AI-generated Key Takeaways
-
The
normalizedDifferencemethod computes the normalized difference between two bands using the formula (first - second) / (first + second). -
If no specific bands are provided, the method defaults to using the first two bands of the image.
-
The output image band is named 'nd', and input image properties are not carried over.
-
Negative pixel values in either input band will result in the corresponding output pixel being masked; to avoid this, use
ee.Image.expression().
ee.Image.expression()
to compute normalized difference. | Usage | Returns |
|---|---|
Image.
normalizedDifference
( bandNames
)
|
Image |
| Argument | Type | Details |
|---|---|---|
|
this:
input
|
Image | The input image. |
bandNames
|
List, default: null | A list of names specifying the bands to use. If not specified, the first and second bands are used. |
Examples
Code Editor (JavaScript)
// A Landsat 8 surface reflectance image. var img = ee . Image ( 'LANDSAT/LC08/C02/T1_L2/LC08_044034_20210508' ); // Calculate normalized difference vegetation index: (NIR - Red) / (NIR + Red). var nirBand = 'SR_B5' ; var redBand = 'SR_B4' ; var ndvi = img . normalizedDifference ([ nirBand , redBand ]); // Display NDVI result on the map. Map . setCenter ( - 122.148 , 37.377 , 11 ); Map . addLayer ( ndvi , { min : 0 , max : 0.5 }, 'NDVI' );
import ee import geemap.core as geemap
Colab (Python)
# A Landsat 8 surface reflectance image. img = ee . Image ( 'LANDSAT/LC08/C02/T1_L2/LC08_044034_20210508' ) # Calculate normalized difference vegetation index: (NIR - Red) / (NIR + Red). nir_band = 'SR_B5' red_band = 'SR_B4' ndvi = img . normalizedDifference ([ nir_band , red_band ]) # Display NDVI result on the map. m = geemap . Map () m . set_center ( - 122.148 , 37.377 , 11 ) m . add_layer ( ndvi , { 'min' : 0 , 'max' : 0.5 }, 'NDVI' ) m

