Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
Stay organized with collections
Save and categorize content based on your preferences.
Computes the normalized difference between two bands. If the bands to use are not specified, uses the first two bands. The normalized difference is computed as (first − second) / (first + second). Note that the returned image band name is 'nd', the input image properties are not retained in the output image, and a negative pixel value in either input band will cause the output pixel to be masked. To avoid masking negative input values, use 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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[[["\u003cp\u003eComputes the normalized difference between two specified or default image bands using the formula (first - second) / (first + second).\u003c/p\u003e\n"],["\u003cp\u003eReturns a single-band image named 'nd' representing the normalized difference.\u003c/p\u003e\n"],["\u003cp\u003eInput image properties are not preserved in the output, and negative input values in either band result in masked output pixels.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eee.Image.expression()\u003c/code\u003e is recommended for handling negative input values and avoiding masking.\u003c/p\u003e\n"]]],[],null,["Computes the normalized difference between two bands. If the bands to use are not specified, uses the first two bands. The normalized difference is computed as (first − second) / (first + second). Note that the returned image band name is 'nd', the input image properties are not retained in the output image, and a negative pixel value in either input band will cause the output pixel to be masked. To avoid masking negative input values, use `ee.Image.expression()` to compute normalized difference.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|---------------------------------------------|---------|\n| Image.normalizedDifference`(`*bandNames*`)` | Image |\n\n| Argument | Type | Details |\n|---------------|---------------------|-----------------------------------------------------------------------------------------------------|\n| this: `input` | Image | The input image. |\n| `bandNames` | List, default: null | A list of names specifying the bands to use. If not specified, the first and second bands are used. |\n\nExamples\n\nCode Editor (JavaScript) \n\n```javascript\n// A Landsat 8 surface reflectance image.\nvar img = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044034_20210508');\n\n// Calculate normalized difference vegetation index: (NIR - Red) / (NIR + Red).\nvar nirBand = 'SR_B5';\nvar redBand = 'SR_B4';\nvar ndvi = img.normalizedDifference([nirBand, redBand]);\n\n// Display NDVI result on the map.\nMap.setCenter(-122.148, 37.377, 11);\nMap.addLayer(ndvi, {min: 0, max: 0.5}, 'NDVI');\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\nColab (Python) \n\n```python\n# A Landsat 8 surface reflectance image.\nimg = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044034_20210508')\n\n# Calculate normalized difference vegetation index: (NIR - Red) / (NIR + Red).\nnir_band = 'SR_B5'\nred_band = 'SR_B4'\nndvi = img.normalizedDifference([nir_band, red_band])\n\n# Display NDVI result on the map.\nm = geemap.Map()\nm.set_center(-122.148, 37.377, 11)\nm.add_layer(ndvi, {'min': 0, 'max': 0.5}, 'NDVI')\nm\n```"]]