Announcement: All noncommercial projects registered to use Earth Engine beforeApril 15, 2025 mustverify noncommercial eligibility to maintain access. If you have not verified by September 26, 2025, your access may be on hold.

ee.ImageCollection.mosaic

  • Composites all images in a collection using the mask.

  • Returns a single Image object.

  • Prioritizes images last to first and fills invalid pixels with preceding valid pixels.

Composites all the images in a collection, using the mask.

UsageReturns
ImageCollection.mosaic()Image
ArgumentTypeDetails
this:collectionImageCollectionThe collection to mosaic.

Examples

Code Editor (JavaScript)

// Sentinel-2 image collection for July 2021 intersecting a point of interest.// Reflectance, cloud probability, and scene classification bands are selected.varcol=ee.ImageCollection('COPERNICUS/S2_SR').filterDate('2021-07-01','2021-08-01').filterBounds(ee.Geometry.Point(-122.373,37.448)).select('B.*|MSK_CLDPRB|SCL');// Visualization parameters for reflectance RGB.varvisRefl={bands:['B11','B8','B3'],min:0,max:4000};Map.setCenter(-122.373,37.448,9);Map.addLayer(col,visRefl,'Collection reference',false);// Reduce the collection to a single image using a variety of methods.varmean=col.mean();Map.addLayer(mean,visRefl,'Mean (B11, B8, B3)');varmedian=col.median();Map.addLayer(median,visRefl,'Median (B11, B8, B3)');varmin=col.min();Map.addLayer(min,visRefl,'Min (B11, B8, B3)');varmax=col.max();Map.addLayer(max,visRefl,'Max (B11, B8, B3)');varsum=col.sum();Map.addLayer(sum,{bands:['MSK_CLDPRB'],min:0,max:500},'Sum (MSK_CLDPRB)');varproduct=col.product();Map.addLayer(product,{bands:['MSK_CLDPRB'],min:0,max:1e10},'Product (MSK_CLDPRB)');// ee.ImageCollection.mode returns the most common value. If multiple mode// values occur, the minimum mode value is returned.varmode=col.mode();Map.addLayer(mode,{bands:['SCL'],min:1,max:11},'Mode (pixel class)');// ee.ImageCollection.count returns the frequency of valid observations. Here,// image pixels are masked based on cloud probability to add valid observation// variability to the collection. Note that pixels with no valid observations// are masked out of the returned image.varnotCloudCol=col.map(function(img){returnimg.updateMask(img.select('MSK_CLDPRB').lte(10));});varcount=notCloudCol.count();Map.addLayer(count,{min:1,max:5},'Count (not cloud observations)');// ee.ImageCollection.mosaic composites images according to their position in// the collection (priority is last to first) and pixel mask status, where// invalid (mask value 0) pixels are filled by preceding valid (mask value >0)// pixels.varmosaic=notCloudCol.mosaic();Map.addLayer(mosaic,visRefl,'Mosaic (B11, B8, B3)');

Python setup

See the Python Environment page for information on the Python API and usinggeemap for interactive development.

importeeimportgeemap.coreasgeemap

Colab (Python)

# Sentinel-2 image collection for July 2021 intersecting a point of interest.# Reflectance, cloud probability, and scene classification bands are selected.col=(ee.ImageCollection('COPERNICUS/S2_SR').filterDate('2021-07-01','2021-08-01').filterBounds(ee.Geometry.Point(-122.373,37.448)).select('B.*|MSK_CLDPRB|SCL'))# Visualization parameters for reflectance RGB.vis_refl={'bands':['B11','B8','B3'],'min':0,'max':4000}m=geemap.Map()m.set_center(-122.373,37.448,9)m.add_layer(col,vis_refl,'Collection reference',False)# Reduce the collection to a single image using a variety of methods.mean=col.mean()m.add_layer(mean,vis_refl,'Mean (B11, B8, B3)')median=col.median()m.add_layer(median,vis_refl,'Median (B11, B8, B3)')min=col.min()m.add_layer(min,vis_refl,'Min (B11, B8, B3)')max=col.max()m.add_layer(max,vis_refl,'Max (B11, B8, B3)')sum=col.sum()m.add_layer(sum,{'bands':['MSK_CLDPRB'],'min':0,'max':500},'Sum (MSK_CLDPRB)')product=col.product()m.add_layer(product,{'bands':['MSK_CLDPRB'],'min':0,'max':1e10},'Product (MSK_CLDPRB)',)# ee.ImageCollection.mode returns the most common value. If multiple mode# values occur, the minimum mode value is returned.mode=col.mode()m.add_layer(mode,{'bands':['SCL'],'min':1,'max':11},'Mode (pixel class)')# ee.ImageCollection.count returns the frequency of valid observations. Here,# image pixels are masked based on cloud probability to add valid observation# variability to the collection. Note that pixels with no valid observations# are masked out of the returned image.not_cloud_col=col.map(lambdaimg:img.updateMask(img.select('MSK_CLDPRB').lte(10)))count=not_cloud_col.count()m.add_layer(count,{'min':1,'max':5},'Count (not cloud observations)')# ee.ImageCollection.mosaic composites images according to their position in# the collection (priority is last to first) and pixel mask status, where# invalid (mask value 0) pixels are filled by preceding valid (mask value >0)# pixels.mosaic=not_cloud_col.mosaic()m.add_layer(mosaic,vis_refl,'Mosaic (B11, B8, B3)')m

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2023-10-06 UTC.