Thông báo: Tất cả dự án phi thương mại đã đăng ký sử dụng Earth Engine trước ngày 15 tháng 4 năm 2025 phải xác minh điều kiện sử dụng phi thương mại để duy trì quyền truy cập vào Earth Engine.
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.
Hãy xem xét ví dụ về việc cần lấy trung bình trên một chuỗi thời gian của hình ảnh được biểu thị bằng ImageCollection. Để giảm ImageCollection, hãy sử dụng imageCollection.reduce(). Điều này làm giảm bộ sưu tập hình ảnh xuống một hình ảnh riêng lẻ như minh hoạ trong Hình 1. Cụ thể, kết quả được tính toán theo từng pixel, sao cho mỗi pixel trong kết quả được tạo thành từ giá trị trung bình của tất cả hình ảnh trong tập hợp tại vị trí đó. Để có được các số liệu thống kê khác, chẳng hạn như trung bình, tổng, độ biến thiên, một phần trăm tuỳ ý, v.v., bạn nên chọn và áp dụng bộ giảm thích hợp. (Xem thẻ Tài liệu trong Trình soạn thảo mã để biết danh sách tất cả các trình giảm hiện có). Đối với các số liệu thống kê cơ bản như tối thiểu, tối đa, trung bình, v.v.,
ImageCollection có các phương thức lối tắt như min(), max(), mean(), v.v. Các phương thức này hoạt động giống hệt như khi gọi reduce(), ngoại trừ tên ban nhạc thu được sẽ không có tên của phương thức giảm được thêm vào.
Hình 1. Hình minh hoạ ee.Reducer được áp dụng cho ImageCollection.
Để biết ví dụ về cách giảm ImageCollection, hãy xem xét một tập hợp hình ảnh Landsat 5, được lọc theo đường dẫn và hàng. Mã sau đây sử dụng reduce() để giảm bộ sưu tập xuống còn một Image (ở đây, một bộ giảm trung bình được sử dụng chỉ để minh hoạ):
Thao tác này sẽ trả về một Image nhiều băng, trong đó mỗi pixel là trung bình của tất cả các pixel chưa bị che trong ImageCollection tại vị trí pixel đó. Cụ thể, hàm rút gọn được lặp lại cho từng dải của hình ảnh đầu vào, nghĩa là giá trị trung bình được tính toán độc lập trong từng dải. Lưu ý rằng tên ban nhạc có tên của hàm giảm được thêm vào: 'B1_median', 'B2_median', v.v. Đầu ra sẽ có dạng như Hình 2.
Để biết thêm thông tin về cách giảm bộ sưu tập hình ảnh, hãy xem phần giảm trong tài liệu về ImageCollection. Cụ thể, hãy lưu ý rằng hình ảnh được tạo bằng cách giảm ImageCollectionkhông có hình chiếu. Điều này có nghĩa là bạn nên đặt rõ ràng tỷ lệ trên mọi phép tính liên quan đến đầu ra hình ảnh được tính toán bằng cách giảm ImageCollection.
Hình 2. Hình ảnh tổng hợp giả màu của trung bình các cảnh trên vệ tinh Landsat 5 trong năm 2008.
[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 reduce an \u003ccode\u003eImageCollection\u003c/code\u003e to a single image by applying a reducer function pixel-wise.\u003c/p\u003e\n"],["\u003cp\u003eEarth Engine provides built-in reducers for common statistics like median, mean, min, max, and more.\u003c/p\u003e\n"],["\u003cp\u003eThe output of \u003ccode\u003ereduce()\u003c/code\u003e is a multi-band image where each pixel represents the reduced value across the input images.\u003c/p\u003e\n"],["\u003cp\u003eBand names in the output image are appended with the reducer name (e.g., \u003ccode\u003eB1_median\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eReduced images have no projection, requiring explicit scale setting for further computations.\u003c/p\u003e\n"]]],[],null,["# ImageCollection Reductions\n\nConsider the example of needing to take the median over a time series of images\nrepresented by an `ImageCollection`. To reduce an `ImageCollection`,\nuse `imageCollection.reduce()`. This reduces the collection of images to an\nindividual image as illustrated in Figure 1. Specifically, the output is computed\npixel-wise, such that each pixel in the output is composed of the median value of all the\nimages in the collection at that location. To get other statistics, such as mean, sum,\nvariance, an arbitrary percentile, etc., the appropriate reducer should be selected and\napplied. (See the **Docs** tab in the\n[Code Editor](https://code.earthengine.google.com) for a list of all the reducers\ncurrently available). For basic statistics like min, max, mean, etc.,\n`ImageCollection` has shortcut methods like `min()`,\n`max()`, `mean()`, etc. They function in exactly the same way\nas calling `reduce()`, except the resultant band names will not have the\nname of the reducer appended.\nFigure 1. Illustration of an ee.Reducer applied to an ImageCollection.\n\nFor an example of reducing an `ImageCollection`, consider a collection of\nLandsat 5 images, filtered by path and row. The following code uses `reduce()`\nto reduce the collection to one `Image` (here a median reducer is used simply\nfor illustrative purposes):\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load an image collection, filtered so it's not too much data.\nvar collection = ee.ImageCollection('LANDSAT/LT05/C02/T1')\n .filterDate('2008-01-01', '2008-12-31')\n .filter(ee.Filter.eq('WRS_PATH', 44))\n .filter(ee.Filter.eq('WRS_ROW', 34));\n\n// Compute the median in each band, each pixel.\n// Band names are B1_median, B2_median, etc.\nvar median = collection.reduce(ee.Reducer.median());\n\n// The output is an Image. Add it to the map.\nvar vis_param = {bands: ['B4_median', 'B3_median', 'B2_median'], gamma: 1.6};\nMap.setCenter(-122.3355, 37.7924, 9);\nMap.addLayer(median, vis_param);\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 an image collection, filtered so it's not too much data.\ncollection = (\n ee.ImageCollection('LANDSAT/LT05/C02/T1')\n .filterDate('2008-01-01', '2008-12-31')\n .filter(ee.Filter.eq('WRS_PATH', 44))\n .filter(ee.Filter.eq('WRS_ROW', 34))\n)\n\n# Compute the median in each band, each pixel.\n# Band names are B1_median, B2_median, etc.\nmedian = collection.reduce(ee.Reducer.median())\n\n# The output is an Image. Add it to the map.\nvis_param = {'bands': ['B4_median', 'B3_median', 'B2_median'], 'gamma': 1.6}\nm = geemap.Map()\nm.set_center(-122.3355, 37.7924, 9)\nm.add_layer(median, vis_param)\nm\n```\n\nThis returns a multi-band `Image`, each pixel of which is the median of all\nunmasked pixels in the `ImageCollection` at that pixel location. Specifically,\nthe reducer has been repeated for each band of the input imagery, meaning that the median\nis computed independently in each band. Note that the band names have the name of the\nreducer appended: `'B1_median'`, `'B2_median'`, etc.\nThe output should look something like Figure 2.\n\nFor more information about reducing image collections, see the\n[reducing section of the `ImageCollection` docs](/earth-engine/guides/ic_reducing). In\nparticular, note that images produced by reducing an `ImageCollection`\n[have no projection](/earth-engine/guides/ic_reducing#composites-have-no-projection). This means\nthat you should explicitly set the scale on any computations involving computed images\noutput by an `ImageCollection` reduction.\nFigure 2. A false color composite of the median of Landsat 5 scenes in 2008."]]