お知らせ :
2025 年 4 月 15 日 より前に Earth Engine の使用を登録したすべての非商用プロジェクトは、アクセスを維持するために
非商用目的での利用資格を確認 する必要があります。2025 年 9 月 26 日までに確認が完了していない場合、アクセスが保留されることがあります。
フィードバックを送信
ee.Image.updateMask
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
既存のマスクがゼロでないすべての位置で、画像のマスクを更新します。出力画像は、入力画像のメタデータとフットプリントを保持します。
用途 戻り値 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 Developers サイトのポリシー をご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-26 UTC。
ご意見をお聞かせください
[[["わかりやすい","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"]],["最終更新日 2025-07-26 UTC。"],[],["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"]]