ee.Image.mask

取得或設定圖片的遮罩。輸出圖片會保留輸入圖片的中繼資料和足跡。如果遮罩從零變更為其他值,系統會將像素填入零,或像素類型範圍內最接近零的值。

用量傳回
Image.mask(mask)圖片
引數類型詳細資料
這個:image圖片輸入圖片。
mask圖片 (預設值:null)遮罩圖片。如果指定,輸入圖片會複製到輸出內容,但會根據這張圖片的值提供遮罩。如果是單一波段,則會用於輸入圖片中的所有波段。如果未指定,則會傳回從輸入圖片遮罩建立的圖片,並縮放至 [0:1] 範圍 (無效 = 0,有效 = 1.0)。

範例

程式碼編輯器 (JavaScript)

// A Sentinel-2 surface reflectance image.
var img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');
var trueColorViz = {
  bands: ['B4', 'B3', 'B2'],
  min: 0,
  max: 2700,
  gamma: 1.3
};
print('Sentinel-2 image', img);
Map.setCenter(-122.36, 37.47, 10);
Map.addLayer(img, trueColorViz, 'Sentinel-2 image');

// Get masks for all image bands; each band has an independent mask.
// Valid pixels are value 1, invalid are 0.
var multiBandMaskImg = img.mask();
print('Multi-band mask image', multiBandMaskImg);
Map.addLayer(multiBandMaskImg, null, 'Multi-band mask image');

// Get the mask for a single image band.
var singleBandMaskImg = img.select('B1').mask();
print('Single-band mask image', singleBandMaskImg);
Map.addLayer(singleBandMaskImg, null, 'Single-band mask image');

Python 設定

請參閱 Python 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

import ee
import geemap.core as geemap

Colab (Python)

# A Sentinel-2 surface reflectance image.
img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG')
true_color_viz = {
    'bands': ['B4', 'B3', 'B2'],
    'min': 0,
    'max': 2700,
    'gamma': 1.3,
}
display('Sentinel-2 image', img)
m = geemap.Map()
m.set_center(-122.36, 37.47, 10)
m.add_layer(img, true_color_viz, 'Sentinel-2 image')

# Get masks for all image bands each band has an independent mask.
# Valid pixels are value 1, invalid are 0.
multi_band_mask_img = img.mask()
display('Multi-band mask image', multi_band_mask_img)
m.add_layer(multi_band_mask_img, None, 'Multi-band mask image')

# Get the mask for a single image band.
single_band_mask_img = img.select('B1').mask()
display('Single-band mask image', single_band_mask_img)
m.add_layer(single_band_mask_img, None, 'Single-band mask image')
m