Giảm ImageCollection
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Để kết hợp hình ảnh trong ImageCollection
, hãy sử dụng imageCollection.reduce()
. Thao tác này sẽ kết hợp tất cả hình ảnh trong bộ sưu tập thành một hình ảnh duy nhất đại diện cho, ví dụ: độ lệch tối thiểu, tối đa, trung bình hoặc chuẩn của hình ảnh.
(Xem phần về phương thức giảm để biết thêm thông tin về phương thức giảm). Ví dụ: để tạo hình ảnh giá trị trung bình từ một bộ sưu tập:
Trình soạn thảo mã (JavaScript)
// Load a Landsat 8 collection for a single path-row.
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
.filter(ee.Filter.eq('WRS_PATH', 44))
.filter(ee.Filter.eq('WRS_ROW', 34))
.filterDate('2014-01-01', '2015-01-01');
// Compute a median image and display.
var median = collection.median();
Map.setCenter(-122.3578, 37.7726, 12);
Map.addLayer(median, {bands: ['B4', 'B3', 'B2'], max: 0.3}, 'Median');
Thiết lập Python
Hãy xem trang
Môi trường Python để biết thông tin về API Python và cách sử dụng geemap
để phát triển tương tác.
import ee
import geemap.core as geemap
Colab (Python)
# Load a Landsat 8 collection for a single path-row.
collection = (
ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
.filter(ee.Filter.eq('WRS_PATH', 44))
.filter(ee.Filter.eq('WRS_ROW', 34))
.filterDate('2014-01-01', '2015-01-01')
)
# Compute a median image and display.
median = collection.median()
m = geemap.Map()
m.set_center(-122.3578, 37.7726, 12)
m.add_layer(median, {'bands': ['B4', 'B3', 'B2'], 'max': 0.3}, 'Median')
m
Tại mỗi vị trí trong hình ảnh đầu ra, trong mỗi dải tần số, giá trị pixel là giá trị trung bình của tất cả các pixel chưa bị che trong hình ảnh đầu vào (các hình ảnh trong tập hợp). Trong ví dụ trước, median()
là một phương thức thuận tiện cho lệnh gọi sau:
Trình soạn thảo mã (JavaScript)
// Reduce the collection with a median reducer.
var median = collection.reduce(ee.Reducer.median());
// Display the median image.
Map.addLayer(median,
{bands: ['B4_median', 'B3_median', 'B2_median'], max: 0.3},
'Also median');
Thiết lập Python
Hãy xem trang
Môi trường Python để biết thông tin về API Python và cách sử dụng geemap
để phát triển tương tác.
import ee
import geemap.core as geemap
Colab (Python)
# Reduce the collection with a median reducer.
median = collection.reduce(ee.Reducer.median())
# Display the median image.
m.add_layer(
median,
{'bands': ['B4_median', 'B3_median', 'B2_median'], 'max': 0.3},
'Also median',
)
m
Xin lưu ý rằng tên ban nhạc khác nhau do sử dụng reduce()
thay vì phương thức thuận tiện. Cụ thể, tên của bộ giảm đã được thêm vào tên ban nhạc.
Bạn cũng có thể giảm số lượng thành phần phức tạp hơn bằng cách sử dụng reduce()
. Ví dụ: để tính toán xu hướng tuyến tính dài hạn trên một tập hợp, hãy sử dụng một trong các trình giảm hồi quy tuyến tính. Mã sau đây tính toán xu hướng tuyến tính của Chỉ số thực vật tăng cường MODIS (EVI):
Trình soạn thảo mã (JavaScript)
// This function adds a band representing the image timestamp.
var addTime = function(image) {
return image.addBands(image.metadata('system:time_start')
// Convert milliseconds from epoch to years to aid in
// interpretation of the following trend calculation.
.divide(1000 * 60 * 60 * 24 * 365));
};
// Load a MODIS collection, filter to several years of 16 day mosaics,
// and map the time band function over it.
var collection = ee.ImageCollection('MODIS/006/MYD13A1')
.filterDate('2004-01-01', '2010-10-31')
.map(addTime);
// Select the bands to model with the independent variable first.
var trend = collection.select(['system:time_start', 'EVI'])
// Compute the linear trend over time.
.reduce(ee.Reducer.linearFit());
// Display the trend with increasing slopes in green, decreasing in red.
Map.setCenter(-96.943, 39.436, 5);
Map.addLayer(
trend,
{min: 0, max: [-100, 100, 10000], bands: ['scale', 'scale', 'offset']},
'EVI trend');
Thiết lập Python
Hãy xem trang
Môi trường Python để biết thông tin về API Python và cách sử dụng geemap
để phát triển tương tác.
import ee
import geemap.core as geemap
Colab (Python)
# This function adds a band representing the image timestamp.
def add_time(image):
return image.addBands(
image.metadata('system:time_start')
# Convert milliseconds from epoch to years to aid in
# interpretation of the following trend calculation.
.divide(1000 * 60 * 60 * 24 * 365)
)
# Load a MODIS collection, filter to several years of 16 day mosaics,
# and map the time band function over it.
collection = (
ee.ImageCollection('MODIS/006/MYD13A1')
.filterDate('2004-01-01', '2010-10-31')
.map(add_time)
)
# Select the bands to model with the independent variable first.
trend = collection.select(['system:time_start', 'EVI']).reduce(
# Compute the linear trend over time.
ee.Reducer.linearFit()
)
# Display the trend with increasing slopes in green, decreasing in red.
m.set_center(-96.943, 39.436, 5)
m = geemap.Map()
m.add_layer(
trend,
{
'min': 0,
'max': [-100, 100, 10000],
'bands': ['scale', 'scale', 'offset'],
},
'EVI trend',
)
m
Xin lưu ý rằng kết quả của việc giảm trong ví dụ này là một hình ảnh hai dải với một dải cho độ dốc của hồi quy tuyến tính (scale
) và một dải cho giá trị chặn (offset
). Hãy khám phá tài liệu API để xem danh sách các phương thức rút gọn có sẵn nhằm rút gọn ImageCollection
thành một Image
.
Thành phần kết hợp không có phép chiếu
Hình ảnh tổng hợp được tạo bằng cách giảm một bộ sưu tập hình ảnh có thể tạo ra các pixel trong bất kỳ phép chiếu nào được yêu cầu và do đó không có phép chiếu đầu ra cố định.
Thay vào đó, các thành phần kết hợp có chế độ chiếu mặc định của WGS-84 với pixel có độ phân giải 1 độ. Các thành phần kết hợp có phép chiếu mặc định sẽ được tính toán theo bất kỳ phép chiếu đầu ra nào được yêu cầu. Yêu cầu xảy ra bằng cách hiển thị thành phần kết hợp trong Trình soạn thảo mã (tìm hiểu cách Trình soạn thảo mã đặt tỷ lệ và mặt chiếu) hoặc bằng cách chỉ định rõ ràng một mặt chiếu/tỷ lệ như trong một tập hợp như ReduceRegion
hoặc Export
.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-25 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[[["\u003cp\u003eUse \u003ccode\u003eimageCollection.reduce()\u003c/code\u003e to composite images in an \u003ccode\u003eImageCollection\u003c/code\u003e into a single image representing a statistical summary (e.g., median, mean) of the collection.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ereduce()\u003c/code\u003e function utilizes reducers like \u003ccode\u003eee.Reducer.median()\u003c/code\u003e to calculate the desired composite, with band names reflecting the reducer used.\u003c/p\u003e\n"],["\u003cp\u003eMore complex reductions, such as calculating linear trends, are possible using specific reducers like \u003ccode\u003eee.Reducer.linearFit()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eComposite images generated from reducing an image collection do not have a fixed projection and will be computed based on the requested output projection.\u003c/p\u003e\n"]]],[],null,["# Reducing an ImageCollection\n\nTo composite images in an `ImageCollection`, use\n`imageCollection.reduce()`. This will composite all the images in the\ncollection to a single image representing, for example, the min, max, mean or standard\ndeviation of the images.\n(See the [Reducers section](/earth-engine/guides/reducers_image_collection)\nfor more information about reducers). For example, to create a median value image from a\ncollection:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load a Landsat 8 collection for a single path-row.\nvar collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')\n .filter(ee.Filter.eq('WRS_PATH', 44))\n .filter(ee.Filter.eq('WRS_ROW', 34))\n .filterDate('2014-01-01', '2015-01-01');\n\n// Compute a median image and display.\nvar median = collection.median();\nMap.setCenter(-122.3578, 37.7726, 12);\nMap.addLayer(median, {bands: ['B4', 'B3', 'B2'], max: 0.3}, 'Median');\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# Load a Landsat 8 collection for a single path-row.\ncollection = (\n ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')\n .filter(ee.Filter.eq('WRS_PATH', 44))\n .filter(ee.Filter.eq('WRS_ROW', 34))\n .filterDate('2014-01-01', '2015-01-01')\n)\n\n# Compute a median image and display.\nmedian = collection.median()\nm = geemap.Map()\nm.set_center(-122.3578, 37.7726, 12)\nm.add_layer(median, {'bands': ['B4', 'B3', 'B2'], 'max': 0.3}, 'Median')\nm\n```\n\nAt each location in the output image, in each band, the pixel value is the median of all\nunmasked pixels in the input imagery (the images in the collection). In the previous\nexample, `median()` is a convenience method for the following call:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Reduce the collection with a median reducer.\nvar median = collection.reduce(ee.Reducer.median());\n\n// Display the median image.\nMap.addLayer(median,\n {bands: ['B4_median', 'B3_median', 'B2_median'], max: 0.3},\n 'Also median');\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# Reduce the collection with a median reducer.\nmedian = collection.reduce(ee.Reducer.median())\n\n# Display the median image.\nm.add_layer(\n median,\n {'bands': ['B4_median', 'B3_median', 'B2_median'], 'max': 0.3},\n 'Also median',\n)\nm\n```\n\nNote that the band names differ as a result of using `reduce()` instead of the\nconvenience method. Specifically, the names of the reducer have been appended to the\nband names.\n\nMore complex reductions are also possible using `reduce()`. For\nexample, to compute the long term linear trend over a collection, use one of the linear\nregression reducers. The following code computes the linear trend of MODIS Enhanced\nVegetation Index (EVI):\n\n### Code Editor (JavaScript)\n\n```javascript\n// This function adds a band representing the image timestamp.\nvar addTime = function(image) {\n return image.addBands(image.metadata('system:time_start')\n // Convert milliseconds from epoch to years to aid in\n // interpretation of the following trend calculation.\n .divide(1000 * 60 * 60 * 24 * 365));\n};\n\n// Load a MODIS collection, filter to several years of 16 day mosaics,\n// and map the time band function over it.\nvar collection = ee.ImageCollection('MODIS/006/MYD13A1')\n .filterDate('2004-01-01', '2010-10-31')\n .map(addTime);\n\n// Select the bands to model with the independent variable first.\nvar trend = collection.select(['system:time_start', 'EVI'])\n // Compute the linear trend over time.\n .reduce(ee.Reducer.linearFit());\n\n// Display the trend with increasing slopes in green, decreasing in red.\nMap.setCenter(-96.943, 39.436, 5);\nMap.addLayer(\n trend,\n {min: 0, max: [-100, 100, 10000], bands: ['scale', 'scale', 'offset']},\n 'EVI trend');\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# This function adds a band representing the image timestamp.\ndef add_time(image):\n return image.addBands(\n image.metadata('system:time_start')\n # Convert milliseconds from epoch to years to aid in\n # interpretation of the following trend calculation.\n .divide(1000 * 60 * 60 * 24 * 365)\n )\n\n\n# Load a MODIS collection, filter to several years of 16 day mosaics,\n# and map the time band function over it.\ncollection = (\n ee.ImageCollection('MODIS/006/MYD13A1')\n .filterDate('2004-01-01', '2010-10-31')\n .map(add_time)\n)\n\n# Select the bands to model with the independent variable first.\ntrend = collection.select(['system:time_start', 'EVI']).reduce(\n # Compute the linear trend over time.\n ee.Reducer.linearFit()\n)\n\n# Display the trend with increasing slopes in green, decreasing in red.\nm.set_center(-96.943, 39.436, 5)\nm = geemap.Map()\nm.add_layer(\n trend,\n {\n 'min': 0,\n 'max': [-100, 100, 10000],\n 'bands': ['scale', 'scale', 'offset'],\n },\n 'EVI trend',\n)\nm\n```\n\nNote that the output of the reduction in this example is a two banded image\nwith one band for the slope of a linear regression (`scale`) and one band\nfor the intercept (`offset`). Explore the API documentation to see a list of\nthe reducers that are available to reduce an `ImageCollection` to a single\n`Image`.\n\nComposites have no projection\n-----------------------------\n\nComposite images created by reducing an image collection are able to produce pixels\nin any requested projection and therefore *have no fixed output projection* .\nInstead, composites have\n[the default\nprojection](/earth-engine/guides/projections#the-default-projection) of WGS-84 with 1-degree resolution pixels. Composites with the default\nprojection will be computed in whatever output projection is requested. A request\noccurs by displaying the composite in the Code Editor (learn about how the Code editor\nsets [scale](/earth-engine/guides/scale#scale-of-analysis) and\n[projection](/earth-engine/guides/projections)), or by explicitly specifying a\nprojection/scale as in an aggregation such as\n`ReduceRegion` or `Export`."]]