Stay organized with collectionsSave and categorize content based on your preferences.
Replaces mask and value of the input image with the mask and value of another image at all positions where the input mask is zero. The output image retains the metadata of the input image. By default, the output image also retains the footprint of the input, but setting sameFootprint to false allows to extend the footprint.
Usage
Returns
Image.unmask(value,sameFootprint)
Image
Argument
Type
Details
this:input
Image
Input image.
value
Image, default: null
New value and mask for the masked pixels of the input image. If not specified, defaults to constant zero image which is valid everywhere.
sameFootprint
Boolean, default: true
If true (or unspecified), the output retains the footprint of the input image. If false, the footprint of the output is the union of the input footprint with the footprint of the value image.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eunmask()\u003c/code\u003e method replaces masked pixel values in an image with specified values or data from another image.\u003c/p\u003e\n"],["\u003cp\u003eIt's used to fill in areas where the input image has invalid or missing data, often represented by a mask with zero values.\u003c/p\u003e\n"],["\u003cp\u003eBy default, the output image retains the original image's footprint, but you can change this behavior using the \u003ccode\u003esameFootprint\u003c/code\u003e parameter.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eunmask()\u003c/code\u003e can be useful for tasks like setting nodata values for export, merging images, or filling gaps in data.\u003c/p\u003e\n"]]],[],null,["# ee.Image.unmask\n\nReplaces mask and value of the input image with the mask and value of another image at all positions where the input mask is zero. The output image retains the metadata of the input image. By default, the output image also retains the footprint of the input, but setting sameFootprint to false allows to extend the footprint.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-----------------------------------------------|---------|\n| Image.unmask`(`*value* `, `*sameFootprint*`)` | Image |\n\n| Argument | Type | Details |\n|-----------------|------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| this: `input` | Image | Input image. |\n| `value` | Image, default: null | New value and mask for the masked pixels of the input image. If not specified, defaults to constant zero image which is valid everywhere. |\n| `sameFootprint` | Boolean, default: true | If true (or unspecified), the output retains the footprint of the input image. If false, the footprint of the output is the union of the input footprint with the footprint of the value image. |\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// Create a Boolean land mask from the SWIR1 band; water is value 0, land is 1.\nvar landMask = img.select('B11').gt(100);\nprint('Land mask', landMask);\nMap.addLayer(landMask, {palette: ['blue', 'lightgreen']}, 'Land mask');\n\n// Apply the single-band land mask to all image bands; pixel values equal to 0\n// in the mask become invalid in the image.\nvar imgMasked = img.updateMask(landMask);\nprint('Image, land only', imgMasked);\nMap.addLayer(imgMasked, trueColorViz, 'Image, land only');\n\n// Set invalid masked pixels to a new value, e.g. a constant nodata value\n// when exporting an image as GeoTIFF.\nvar imgUnmasked = imgMasked.unmask(32767);\nprint('Image, unmasked', imgMasked);\nMap.addLayer(imgUnmasked, trueColorViz, 'Image, unmasked');\n\n// Reset masked pixels to valid, fill with default value 0, input footprint.\nvar maskResetFootprint = imgMasked.unmask();\nprint('Image mask reset, footprint', maskResetFootprint);\nMap.addLayer(maskResetFootprint, trueColorViz, 'Image mask reset, footprint');\n\n// Reset masked pixels to valid, fill with default value 0, everywhere.\nvar maskResetEverywhere = imgMasked.unmask({sameFootprint: false});\nprint('Image mask reset, everywhere', maskResetEverywhere);\nMap.addLayer(maskResetEverywhere, trueColorViz, 'Image mask reset, everywhere');\n\n// Fill masked pixels with pixels from a different image.\nvar fill = ee.Image('COPERNICUS/S2_SR/20200618T184919_20200618T190341_T10SEG');\nvar imgFilled = imgMasked.unmask(fill);\nprint('Image, filled', imgFilled);\nMap.addLayer(imgFilled, trueColorViz, 'Image, filled');\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# Create a Boolean land mask from the SWIR1 band water is value 0, land is 1.\nland_mask = img.select('B11').gt(100)\ndisplay('Land mask', land_mask)\nm.add_layer(land_mask, {'palette': ['blue', 'lightgreen']}, 'Land mask')\n\n# Apply the single-band land mask to all image bands pixel values equal to 0\n# in the mask become invalid in the image.\nimg_masked = img.updateMask(land_mask)\ndisplay('Image, land only', img_masked)\nm.add_layer(img_masked, true_color_viz, 'Image, land only')\n\n# Set invalid masked pixels to a new value, e.g. a constant nodata value\n# when exporting an image as GeoTIFF.\nimg_unmasked = img_masked.unmask(32767)\ndisplay('Image, unmasked', img_masked)\nm.add_layer(img_unmasked, true_color_viz, 'Image, unmasked')\n\n# Reset masked pixels to valid, fill with default value 0, input footprint.\nmask_reset_footprint = img_masked.unmask()\ndisplay('Image mask reset, footprint', mask_reset_footprint)\nm.add_layer(mask_reset_footprint, true_color_viz, 'Image mask reset, footprint')\n\n# Reset masked pixels to valid, fill with default value 0, everywhere.\nmask_reset_everywhere = img_masked.unmask(sameFootprint=False)\ndisplay('Image mask reset, everywhere', mask_reset_everywhere)\nm.add_layer(\n mask_reset_everywhere, true_color_viz, 'Image mask reset, everywhere'\n)\n\n# Fill masked pixels with pixels from a different image.\nfill = ee.Image('COPERNICUS/S2_SR/20200618T184919_20200618T190341_T10SEG')\nimg_filled = img_masked.unmask(fill)\ndisplay('Image, filled', img_filled)\nm.add_layer(img_filled, true_color_viz, 'Image, filled')\nm\n```"]]