公告 :所有在
2025 年 4 月 15 日 之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件 ,才能继续使用 Earth Engine。
发送反馈
电视春晚仍是不可或缺的文化大餐
更新现有遮罩不为零的所有位置的图片遮罩。输出图片会保留输入图片的元数据和覆盖区。
百度 西南民族大学教授罗新本长期研究四川的骰子,他推测,这个陀螺骰子可能是当时小娃娃的玩具。
用法 返回 Image. updateMask (mask)
图片
参数 类型 详细信息 此:image
图片 输入图片。 mask
图片 图片的新遮罩,以介于 [0, 1] 范围内的浮点值表示(无效 = 0,有效 = 1)。如果此图片具有单个波段,则用于输入图片中的所有波段;否则,必须具有与输入图片相同的波段数。
示例
代码编辑器 (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' );
// Create a Boolean land mask from the SWIR1 band; water is value 0, land is 1.
var landMask = img . select ( 'B11' ). gt ( 100 );
print ( 'Land mask' , landMask );
Map . addLayer ( landMask , { palette : [ 'blue' , 'lightgreen' ]}, 'Land mask' );
// Apply the single-band land mask to all image bands; pixel values equal to 0
// in the mask become invalid in the image.
var imgMasked = img . updateMask ( landMask );
print ( 'Image, land only' , imgMasked );
Map . addLayer ( imgMasked , trueColorViz , 'Image, land only' );
// Masks are band-specific. Here, a multi-band mask image is used to update
// corresponding input image band masks.
var imgBandSubset = img . select ([ 'B4' , 'B3' , 'B2' ]);
var bandSpecificMasks = imgBandSubset . gt ( 200 );
var imgBandSubsetMasked = imgBandSubset . updateMask ( bandSpecificMasks );
print ( 'Multi-band mask image' , bandSpecificMasks );
print ( 'Image, variable band masks' , imgBandSubsetMasked );
Map . addLayer ( bandSpecificMasks , null , 'Multi-band mask image' );
Map . addLayer ( imgBandSubsetMasked , trueColorViz , 'Image, variable band masks' );
// Note that there is only a single alpha channel for visualization, so when
// the ee.Image is rendered as an RGB image or map tiles, a masked pixel in any
// band will result in transparency for all bands.
// Floating point mask values between 0 and 1 will be used to define opacity
// in visualization via Map.addLayer and ee.Image.visualize.
var landMaskFloat = landMask . add ( 0.65 );
var imgMaskedFloat = img . updateMask ( landMaskFloat );
print ( 'Image, partially transparent' , imgMaskedFloat );
Map . addLayer ( imgMaskedFloat , trueColorViz , 'Image, partially transparent' );
Python 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境 页面。
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' )
# Create a Boolean land mask from the SWIR1 band water is value 0, land is 1.
land_mask = img . select ( 'B11' ) . gt ( 100 )
display ( 'Land mask' , land_mask )
m . add_layer ( land_mask , { 'palette' : [ 'blue' , 'lightgreen' ]}, 'Land mask' )
# Apply the single-band land mask to all image bands pixel values equal to 0
# in the mask become invalid in the image.
img_masked = img . updateMask ( land_mask )
display ( 'Image, land only' , img_masked )
m . add_layer ( img_masked , true_color_viz , 'Image, land only' )
# Masks are band-specific. Here, a multi-band mask image is used to update
# corresponding input image band masks.
img_band_subset = img . select ([ 'B4' , 'B3' , 'B2' ])
band_specific_masks = img_band_subset . gt ( 200 )
img_band_subset_masked = img_band_subset . updateMask ( band_specific_masks )
display ( 'Multi-band mask image' , band_specific_masks )
display ( 'Image, variable band masks' , img_band_subset_masked )
m . add_layer ( band_specific_masks , None , 'Multi-band mask image' )
m . add_layer (
img_band_subset_masked , true_color_viz , 'Image, variable band masks'
)
# Note that there is only a single alpha channel for visualization, so when
# the ee.Image is rendered as an RGB image or map tiles, a masked pixel in any
# band will result in transparency for all bands.
# Floating point mask values between 0 and 1 will be used to define opacity
# in visualization via m.add_ee_layer and ee.Image.visualize.
land_mask_float = land_mask . add ( 0.65 )
img_masked_float = img . updateMask ( land_mask_float )
display ( 'Image, partially transparent' , img_masked_float )
m . add_layer ( img_masked_float , true_color_viz , 'Image, partially transparent' )
m
发送反馈
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可 获得了许可,并且代码示例已根据 Apache 2.0 许可 获得了许可。有关详情,请参阅 Google 开发者网站政策 。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-05。
需要向我们提供更多信息?
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-05。"],[[["`updateMask()` modifies an image's mask, making pixels with a mask value of 0 invalid."],["It accepts a single or multi-band image as a mask, applying it to corresponding bands in the input image."],["The input image's metadata and footprint are preserved in the output."],["Floating point mask values (0-1) control pixel opacity during visualization."]]],["The `updateMask()` function modifies an image's existing mask. It takes a new mask as input, a floating-point image where 0 denotes invalid and 1 denotes valid pixels. When applied, the function updates all image pixels where the current mask is non-zero. The new mask can be single-band, affecting all input image bands, or multi-band, updating bands individually. Mask values between 0 and 1 indicate partial transparency. The output image keeps the input image's metadata and footprint.\n"]]