AI-generated Key Takeaways
-
Computes the normalized difference between two specified or default image bands using the formula (first - second) / (first + second).
-
Returns a single-band image named 'nd' representing the normalized difference.
-
Input image properties are not preserved in the output, and negative input values in either band result in masked output pixels.
-
ee.Image.expression()
is recommended for handling negative input values and avoiding masking.
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