ee.Image.normalizedDifference

計算兩個波段之間的標準化差異。如未指定要使用的頻帶,系統會使用前兩個頻帶。標準化差異的計算方式為 (第一個值 − 第二個值) / (第一個值 + 第二個值)。請注意,傳回的影像波段名稱為「nd」,輸入影像屬性不會保留在輸出影像中,且任一輸入波段中的負像素值都會導致輸出像素遭到遮蓋。為避免遮蓋負數輸入值,請使用 ee.Image.expression() 計算標準化差異。

用量傳回
Image.normalizedDifference(bandNames)圖片
引數類型詳細資料
這個:input圖片輸入圖片。
bandNames清單,預設值為空值指定要使用的頻帶名稱清單。如未指定,系統會使用第一和第二個頻帶。

範例

程式碼編輯器 (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 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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