ee.Image.mask

Ruft die Maske eines Bildes ab oder legt sie fest. Das Ausgabebild behält die Metadaten und den Footprint des Eingabebilds bei. Pixel, bei denen sich die Maske von null in einen anderen Wert ändert, werden mit Nullen oder den Werten gefüllt, die im Bereich des Pixeltyps am nächsten an null liegen.

NutzungAusgabe
Image.mask(mask)Bild
ArgumentTypDetails
So gehts: imageBildDas Eingabebild.
maskBild, Standardwert: nullDas Maskenbild. Wenn angegeben, wird das Eingabebild in die Ausgabe kopiert, aber durch die Werte dieses Bilds maskiert. Wenn es sich um ein einzelnes Band handelt, wird es für alle Bänder im Eingabebild verwendet. Wenn nicht angegeben, wird ein Bild zurückgegeben, das aus der Maske des Eingabebilds erstellt und auf den Bereich [0:1] skaliert wurde (ungültig = 0, gültig = 1,0).

Beispiele

Code-Editor (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 einrichten

Informationen zur Python API und zur Verwendung von geemap für die interaktive Entwicklung finden Sie auf der Seite Python-Umgebung.

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