公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.Image.normalizedDifference
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
计算两个波段之间的归一化差异。如果未指定要使用的波段,则使用前两个波段。归一化差值的计算公式为(第一个值 - 第二个值)/(第一个值 + 第二个值)。请注意,返回的影像波段名称为“nd”,输入影像属性不会保留在输出影像中,并且任一输入波段中的负像素值都会导致输出像素被遮盖。为避免屏蔽负输入值,请使用
ee.Image.expression()
计算归一化差值。
用法 | 返回 |
---|
Image.normalizedDifference(bandNames) | 图片 |
参数 | 类型 | 详细信息 |
---|
此:input | 图片 | 输入图片。 |
bandNames | 列表,默认值:null | 一个名称列表,用于指定要使用的频段。如果未指定,则使用第一个频段和第二个频段。 |
示例
代码编辑器 (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');
Python 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
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
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\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,["# ee.Image.normalizedDifference\n\nComputes 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--------\n\n### Code 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\n### Colab (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```"]]