ee.Image.arrayMask

Crée une image de tableau où chaque pixel à valeur de tableau est masqué avec un autre pixel à valeur de tableau, en ne conservant que les éléments où le masque est non nul. Si l 'image de masque comporte une bande, elle sera appliquée à toutes les bandes de l'entrée. Sinon, elles doivent comporter le même nombre de bandes.

UtilisationRenvoie
Image.arrayMask(mask)Image
ArgumentTypeDétails
ceci : inputImageTableau d'image à masquer.
maskImageTableau d'image à masquer.

Exemples

Éditeur de code (JavaScript)

// A function to print arrays for a selected pixel in the following examples.
function sampArrImg(arrImg) {
  var point = ee.Geometry.Point([-121, 42]);
  return arrImg.sample(point, 500).first().get('array');
}

// Create a 1D array image with length 6.
var arrayImg1D = ee.Image([0, 1, 2, 4, 0, 5]).toArray();
print('1D array image (pixel)', sampArrImg(arrayImg1D));
// [0, 1, 2, 4, 0, 5]

// Create a mask using a relational operator to mask values greater than 2.
var mask1D = arrayImg1D.lte(2);
print('1D mask for greater than value 2 (pixel)', sampArrImg(mask1D));
// [1, 1, 1, 0, 1, 0]

var arrayImg1DMask = arrayImg1D.arrayMask(mask1D);
print('1D array image mask (pixel)', sampArrImg(arrayImg1DMask));
// [0, 1, 2, 0]

// Self mask the 1D array image. Value zero will be masked out.
var arrayImg1DselfMask = arrayImg1D.arrayMask(arrayImg1D);
print('1D array image self mask (pixel)', sampArrImg(arrayImg1DselfMask));
// [1, 2, 4, 5]

// Create a 2D array image.
var arrayImg2D = arrayImg1D.arrayReshape(ee.Image([2, 3]).toArray(), 2);
print('2D 2x3 array image (pixel)', sampArrImg(arrayImg2D));
// [[0, 1, 2],
//  [4, 0, 5]]

// Slice out a row to use as a column mask.
var rowAsMaskForCols = arrayImg2D.arraySlice(0, 1, 2);
print('2D mask for cols (pixel)', sampArrImg(rowAsMaskForCols));
// [[4, 0, 5]]

var arrayImg2DMaskCols = arrayImg2D.arrayMask(rowAsMaskForCols);
print('2D array image cols masked (pixel)', sampArrImg(arrayImg2DMaskCols));
// [[0, 2],
//  [4, 5]]

// Slice out a column to use as a row mask.
var colAsMaskForRows = arrayImg2D.arraySlice(1, 1, 2);
print('2D mask for rows (pixel)', sampArrImg(colAsMaskForRows));
// [[1],
//  [0]]

var arrayImg2DMaskRows = arrayImg2D.arrayMask(colAsMaskForRows);
print('2D array image rows masked (pixel)', sampArrImg(arrayImg2DMaskRows));
// [[0, 1, 2]]

Configuration de Python

Consultez la page Environnement Python pour en savoir plus sur l'API Python et sur l'utilisation de geemap pour le développement interactif.

import ee
import geemap.core as geemap

Colab (Python)

# A function to print arrays for a selected pixel in the following examples.
def samp_arr_img(arr_img):
  point = ee.Geometry.Point([-121, 42])
  return arr_img.sample(point, 500).first().get('array')

# Create a 1D array image with length 6.
array_img_1d = ee.Image([0, 1, 2, 4, 0, 5]).toArray()
print('1D array image (pixel):', samp_arr_img(array_img_1d).getInfo())
# [0, 1, 2, 4, 0, 5]

# Create a mask using a relational operator to mask values greater than 2.
mask_1d = array_img_1d.lte(2)
print(
    '1D mask for greater than value 2 (pixel):',
    samp_arr_img(mask_1d).getInfo()
)
# [1, 1, 1, 0, 1, 0]

array_img1d_mask = array_img_1d.arrayMask(mask_1d)
print('1D array image mask (pixel):', samp_arr_img(array_img1d_mask).getInfo())
# [0, 1, 2, 0]

# Self mask the 1D array image. Value zero will be masked out.
array_img_1d_self_mask = array_img_1d.arrayMask(array_img_1d)
print(
    '1D array image self mask (pixel):',
    samp_arr_img(array_img_1d_self_mask).getInfo()
)
# [1, 2, 4, 5]

# Create a 2D array image.
array_img_2d = array_img_1d.arrayReshape(ee.Image([2, 3]).toArray(), 2)
print('2D 2x3 array image (pixel):', samp_arr_img(array_img_2d).getInfo())
# [[0, 1, 2],
#  [4, 0, 5]]

# Slice out a row to use as a column mask.
row_as_mask_for_cols = array_img_2d.arraySlice(0, 1, 2)
print('2D mask for cols (pixel):', samp_arr_img(row_as_mask_for_cols).getInfo())
# [[4, 0, 5]]

array_img_2d_mask_cols = array_img_2d.arrayMask(row_as_mask_for_cols);
print(
    '2D array image cols masked (pixel):',
    samp_arr_img(array_img_2d_mask_cols).getInfo()
)
# [[0, 2],
#  [4, 5]]

# Slice out a column to use as a row mask.
col_as_mask_for_rows = array_img_2d.arraySlice(1, 1, 2)
print('2D mask for rows (pixel):', samp_arr_img(col_as_mask_for_rows).getInfo())
# [[1],
#  [0]]

array_img_2d_mask_rows = array_img_2d.arrayMask(col_as_mask_for_rows)
print(
    '2D array image rows masked (pixel):',
    samp_arr_img(array_img_2d_mask_rows).getInfo()
)
# [[0, 1, 2]]