Anuncio: Todos los proyectos no comerciales registrados para usar Earth Engine antes del 15 de abril de 2025 deben verificar su elegibilidad no comercial para mantener el acceso a Earth Engine.
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Obtiene o establece la máscara de una imagen. La imagen de salida conserva los metadatos y la huella de la imagen de entrada. Los píxeles en los que la máscara cambia de cero a otro valor se completarán con ceros o con los valores más cercanos a cero dentro del rango del tipo de píxel.
Uso
Muestra
Image.mask(mask)
Imagen
Argumento
Tipo
Detalles
esta: image
Imagen
Es la imagen de entrada.
mask
Imagen, valor predeterminado: nulo
Es la imagen de la máscara. Si se especifica, la imagen de entrada se copia en la salida, pero se le aplica la máscara según los valores de esta imagen. Si se trata de una sola banda, se usa para todas las bandas de la imagen de entrada. Si no se especifica, devuelve una imagen creada a partir de la máscara de la imagen de entrada, ajustada al rango [0:1] (inválida = 0, válida = 1.0).
[null,null,["Última actualización: 2025-07-26 (UTC)"],[[["\u003cp\u003e\u003ccode\u003eImage.mask()\u003c/code\u003e retrieves or sets an image's mask, impacting pixel values based on the mask's transitions.\u003c/p\u003e\n"],["\u003cp\u003eWhen retrieving a mask, \u003ccode\u003eImage.mask()\u003c/code\u003e returns a new image representing the mask, scaled to 0-1, where 0 is invalid and 1 is valid.\u003c/p\u003e\n"],["\u003cp\u003eWhen setting a mask, \u003ccode\u003eImage.mask()\u003c/code\u003e is deprecated in favor of \u003ccode\u003eImage.updateMask\u003c/code\u003e and \u003ccode\u003eImage.unmask\u003c/code\u003e for more controlled mask manipulation.\u003c/p\u003e\n"],["\u003cp\u003eThe output image retains the original image's metadata and footprint.\u003c/p\u003e\n"],["\u003cp\u003eMasks can be applied to individual bands or to the entire image.\u003c/p\u003e\n"]]],[],null,["# ee.Image.mask\n\nGets or sets an image's mask. The output image retains the metadata and footprint of the input image. Pixels where the mask changes from zero to another value will be filled with zeros, or the values closest to zero within the range of the pixel type.\n\n\u003cbr /\u003e\n\n| **Note:** the version that sets a mask will be deprecated. To set a mask from an image on previously unmasked pixels, use Image.updateMask. To unmask previously masked pixels, use Image.unmask.\n\n| Usage | Returns |\n|------------------------|---------|\n| Image.mask`(`*mask*`)` | Image |\n\n| Argument | Type | Details |\n|---------------|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| this: `image` | Image | The input image. |\n| `mask` | Image, default: null | The mask image. If specified, the input image is copied to the output but given the mask by the values of this image. If this is a single band, it is used for all bands in the input image. If not specified, returns an image created from the mask of the input image, scaled to the range \\[0:1\\] (invalid = 0, valid = 1.0). |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// A Sentinel-2 surface reflectance image.\nvar img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');\nvar trueColorViz = {\n bands: ['B4', 'B3', 'B2'],\n min: 0,\n max: 2700,\n gamma: 1.3\n};\nprint('Sentinel-2 image', img);\nMap.setCenter(-122.36, 37.47, 10);\nMap.addLayer(img, trueColorViz, 'Sentinel-2 image');\n\n// Get masks for all image bands; each band has an independent mask.\n// Valid pixels are value 1, invalid are 0.\nvar multiBandMaskImg = img.mask();\nprint('Multi-band mask image', multiBandMaskImg);\nMap.addLayer(multiBandMaskImg, null, 'Multi-band mask image');\n\n// Get the mask for a single image band.\nvar singleBandMaskImg = img.select('B1').mask();\nprint('Single-band mask image', singleBandMaskImg);\nMap.addLayer(singleBandMaskImg, null, 'Single-band mask image');\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 Sentinel-2 surface reflectance image.\nimg = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG')\ntrue_color_viz = {\n 'bands': ['B4', 'B3', 'B2'],\n 'min': 0,\n 'max': 2700,\n 'gamma': 1.3,\n}\ndisplay('Sentinel-2 image', img)\nm = geemap.Map()\nm.set_center(-122.36, 37.47, 10)\nm.add_layer(img, true_color_viz, 'Sentinel-2 image')\n\n# Get masks for all image bands each band has an independent mask.\n# Valid pixels are value 1, invalid are 0.\nmulti_band_mask_img = img.mask()\ndisplay('Multi-band mask image', multi_band_mask_img)\nm.add_layer(multi_band_mask_img, None, 'Multi-band mask image')\n\n# Get the mask for a single image band.\nsingle_band_mask_img = img.select('B1').mask()\ndisplay('Single-band mask image', single_band_mask_img)\nm.add_layer(single_band_mask_img, None, 'Single-band mask image')\nm\n```"]]