公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
ee.ImageCollection.mosaic
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
使用遮罩合成集合中的所有圖片。
用量 | 傳回 |
---|
ImageCollection.mosaic() | 圖片 |
引數 | 類型 | 詳細資料 |
---|
這個:collection | ImageCollection | 要製作馬賽克的集合。 |
範例
程式碼編輯器 (JavaScript)
// Sentinel-2 image collection for July 2021 intersecting a point of interest.
// Reflectance, cloud probability, and scene classification bands are selected.
var 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.
var visRefl = {
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.
var mean = col.mean();
Map.addLayer(mean, visRefl, 'Mean (B11, B8, B3)');
var median = col.median();
Map.addLayer(median, visRefl, 'Median (B11, B8, B3)');
var min = col.min();
Map.addLayer(min, visRefl, 'Min (B11, B8, B3)');
var max = col.max();
Map.addLayer(max, visRefl, 'Max (B11, B8, B3)');
var sum = col.sum();
Map.addLayer(sum,
{bands: ['MSK_CLDPRB'], min: 0, max: 500}, 'Sum (MSK_CLDPRB)');
var product = 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.
var mode = 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.
var notCloudCol = col.map(function(img) {
return img.updateMask(img.select('MSK_CLDPRB').lte(10));
});
var count = 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.
var mosaic = notCloudCol.mosaic();
Map.addLayer(mosaic, visRefl, 'Mosaic (B11, B8, B3)');
Python 設定
請參閱
Python 環境頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
import ee
import geemap.core as geemap
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(
lambda img: 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
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003e\u003ccode\u003eImageCollection.mosaic()\u003c/code\u003e composites all images within a collection based on their order and mask status.\u003c/p\u003e\n"],["\u003cp\u003eThe function prioritizes images later in the collection and uses valid pixels to fill in invalid ones from earlier images.\u003c/p\u003e\n"],["\u003cp\u003eInvalid pixels have a mask value of 0, while valid pixels have a mask value greater than 0.\u003c/p\u003e\n"],["\u003cp\u003eThis method is useful for creating cloud-free composites or filling in gaps in image coverage.\u003c/p\u003e\n"]]],["The `mosaic()` function composites images within an `ImageCollection` into a single `Image`. It prioritizes the order of images from last to first in the collection. The pixel mask status also plays a role, invalid pixels (mask value 0) are filled by valid pixels (mask value \u003e 0) from preceding images. This function can be used in both JavaScript and Python. Several other reduction functions are exemplified.\n"],null,["# ee.ImageCollection.mosaic\n\nComposites all the images in a collection, using the mask.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|----------------------------|---------|\n| ImageCollection.mosaic`()` | Image |\n\n| Argument | Type | Details |\n|--------------------|-----------------|---------------------------|\n| this: `collection` | ImageCollection | The collection to mosaic. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// Sentinel-2 image collection for July 2021 intersecting a point of interest.\n// Reflectance, cloud probability, and scene classification bands are selected.\nvar col = ee.ImageCollection('COPERNICUS/S2_SR')\n .filterDate('2021-07-01', '2021-08-01')\n .filterBounds(ee.Geometry.Point(-122.373, 37.448))\n .select('B.*|MSK_CLDPRB|SCL');\n\n// Visualization parameters for reflectance RGB.\nvar visRefl = {\n bands: ['B11', 'B8', 'B3'],\n min: 0,\n max: 4000\n};\nMap.setCenter(-122.373, 37.448, 9);\nMap.addLayer(col, visRefl, 'Collection reference', false);\n\n// Reduce the collection to a single image using a variety of methods.\nvar mean = col.mean();\nMap.addLayer(mean, visRefl, 'Mean (B11, B8, B3)');\n\nvar median = col.median();\nMap.addLayer(median, visRefl, 'Median (B11, B8, B3)');\n\nvar min = col.min();\nMap.addLayer(min, visRefl, 'Min (B11, B8, B3)');\n\nvar max = col.max();\nMap.addLayer(max, visRefl, 'Max (B11, B8, B3)');\n\nvar sum = col.sum();\nMap.addLayer(sum,\n {bands: ['MSK_CLDPRB'], min: 0, max: 500}, 'Sum (MSK_CLDPRB)');\n\nvar product = col.product();\nMap.addLayer(product,\n {bands: ['MSK_CLDPRB'], min: 0, max: 1e10}, 'Product (MSK_CLDPRB)');\n\n// ee.ImageCollection.mode returns the most common value. If multiple mode\n// values occur, the minimum mode value is returned.\nvar mode = col.mode();\nMap.addLayer(mode, {bands: ['SCL'], min: 1, max: 11}, 'Mode (pixel class)');\n\n// ee.ImageCollection.count returns the frequency of valid observations. Here,\n// image pixels are masked based on cloud probability to add valid observation\n// variability to the collection. Note that pixels with no valid observations\n// are masked out of the returned image.\nvar notCloudCol = col.map(function(img) {\n return img.updateMask(img.select('MSK_CLDPRB').lte(10));\n});\nvar count = notCloudCol.count();\nMap.addLayer(count, {min: 1, max: 5}, 'Count (not cloud observations)');\n\n// ee.ImageCollection.mosaic composites images according to their position in\n// the collection (priority is last to first) and pixel mask status, where\n// invalid (mask value 0) pixels are filled by preceding valid (mask value \u003e0)\n// pixels.\nvar mosaic = notCloudCol.mosaic();\nMap.addLayer(mosaic, visRefl, 'Mosaic (B11, B8, B3)');\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# Sentinel-2 image collection for July 2021 intersecting a point of interest.\n# Reflectance, cloud probability, and scene classification bands are selected.\ncol = (\n ee.ImageCollection('COPERNICUS/S2_SR')\n .filterDate('2021-07-01', '2021-08-01')\n .filterBounds(ee.Geometry.Point(-122.373, 37.448))\n .select('B.*|MSK_CLDPRB|SCL')\n)\n\n# Visualization parameters for reflectance RGB.\nvis_refl = {'bands': ['B11', 'B8', 'B3'], 'min': 0, 'max': 4000}\nm = geemap.Map()\nm.set_center(-122.373, 37.448, 9)\nm.add_layer(col, vis_refl, 'Collection reference', False)\n\n# Reduce the collection to a single image using a variety of methods.\nmean = col.mean()\nm.add_layer(mean, vis_refl, 'Mean (B11, B8, B3)')\n\nmedian = col.median()\nm.add_layer(median, vis_refl, 'Median (B11, B8, B3)')\n\nmin = col.min()\nm.add_layer(min, vis_refl, 'Min (B11, B8, B3)')\n\nmax = col.max()\nm.add_layer(max, vis_refl, 'Max (B11, B8, B3)')\n\nsum = col.sum()\nm.add_layer(\n sum, {'bands': ['MSK_CLDPRB'], 'min': 0, 'max': 500}, 'Sum (MSK_CLDPRB)'\n)\n\nproduct = col.product()\nm.add_layer(\n product,\n {'bands': ['MSK_CLDPRB'], 'min': 0, 'max': 1e10},\n 'Product (MSK_CLDPRB)',\n)\n\n# ee.ImageCollection.mode returns the most common value. If multiple mode\n# values occur, the minimum mode value is returned.\nmode = col.mode()\nm.add_layer(\n mode, {'bands': ['SCL'], 'min': 1, 'max': 11}, 'Mode (pixel class)'\n)\n\n# ee.ImageCollection.count returns the frequency of valid observations. Here,\n# image pixels are masked based on cloud probability to add valid observation\n# variability to the collection. Note that pixels with no valid observations\n# are masked out of the returned image.\nnot_cloud_col = col.map(\n lambda img: img.updateMask(img.select('MSK_CLDPRB').lte(10))\n)\ncount = not_cloud_col.count()\nm.add_layer(count, {'min': 1, 'max': 5}, 'Count (not cloud observations)')\n\n# ee.ImageCollection.mosaic composites images according to their position in\n# the collection (priority is last to first) and pixel mask status, where\n# invalid (mask value 0) pixels are filled by preceding valid (mask value \u003e0)\n# pixels.\nmosaic = not_cloud_col.mosaic()\nm.add_layer(mosaic, vis_refl, 'Mosaic (B11, B8, B3)')\nm\n```"]]