Google Earth Engine Tutorial: Beginners Guide 10 Reduce Image Collection
Credit: Youtube Channel “Terra Spatial, Tutorial on using reduction operations to process and analyze image collections in Google Earth Engine.”
You can see all the tutorials from here: Techgeo Academy.
Google Earth Engine (GEE) is a powerful platform for geospatial analysis and remote sensing. One of its core functionalities is reducing an image collection to a single image or feature collection. This process is essential for aggregating data over time, space, or other dimensions. Here’s a beginner’s guide to help you understand how to implement reduce operations on image collections in GEE.
Understanding Image Collections in GEE
In GEE, an image collection is a list of images that share similar properties, such as a specific sensor, date range, or location. Reducing an image collection allows you to combine these images using statistical methods or other aggregation techniques. This is achieved using the reduce()
function, which applies a reducer to each pixel across the entire collection.
How to Reduce an Image Collection
To reduce an image collection, you first need to define the collection, then apply the reduce()
method with a specific reducer. Below are the key steps to follow:
- Access the Image Collection: Use a dataset available in GEE, like Landsat or MODIS. For example,
ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
. - Define the Reducer: Choose a reducer based on your analysis goals. Common reducers include
sum()
,mean()
,max()
,min()
, andmedian()
. - Apply the Reduction: Call the
reduce()
method on the image collection. For example,.reduce(ee.Reducer.sum())
. - Visualize the Output: Display the resulting image using
Map.addLayer()
or export it to Google Drive for further analysis.
Example: Reduce an Image Collection to a Mean Image
Let’s demonstrate how to calculate the mean of a Landsat 8 surface reflectance image collection for a given region and timeframe:
// Load the image collection
var collection = ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
.filterDate('2020-01-01', '2020-12-31')
.filterBounds(ee.Geometry.Rectangle([-122.5, 37.0, -121.5, 38.0]));
// Reduce the collection using mean
var meanImage = collection.reduce(ee.Reducer.mean());
// Display the result
Map.setCenter(-122, 37.5, 10);
Map.addLayer(meanImage, {bands: ['SR_B4', 'SR_B3', 'SR_B2'], min: 0, max: 0.3}, 'Mean Image');
Common Reducers and Their Use Cases
The ee.Reducer
class provides various methods to aggregate data. Here are some examples:
- sum(): Calculates the total value of all pixels in the collection.
- mean(): Computes the average value per pixel across the collection.
- max(): Identifies the highest pixel value in the collection.
- min(): Identifies the lowest pixel value in the collection.
- median(): Finds the middle value of all pixels for each band.
- mode(): Determines the most frequent pixel value in the collection.
Reducers can also be combined with ee.Reducer[“bandwise”]()
for per-band operations or ee.Reducer[“medianAbsoluteDeviation”]()
for statistical variability analysis.
Reducing Image Collections by Date or Region
Reduction can be tailored to specific dates or regions. For instance, to calculate the maximum value for each month:
// Aggregate by date
var monthlyMax = collection
.map(function(image) {
return image.set('month', image.date().get('month'));
})
.reduce(ee.Reducer.max(), 1);
Or, to reduce a collection over a specific region, use filterBounds()
before applying reduce()
.
FAQ
What is the difference between reduce()
and reduceRegions()
?
reduce()
aggregates all pixels in the image collection, resulting in a single image with per-pixel statistics. reduceRegions()
aggregates pixel values within specified geometries, returning a feature collection with aggregated values for each region.
Can I reduce multiple bands at once?
Yes, when using a reducer like mean()
, it automatically applies to all bands. You can also use rename()
or select()
to target specific bands before reduction.
How do I visualize the reduced image?
Use Map.addLayer()
with appropriate band parameters. For example, if reducing a year’s worth of data, specify the bands for RGB visualization and adjust the min/max values for optimal contrast.
What if my dataset is too large for a single reduce operation?
For large collections, consider filtering the images first or using chunk()
to process data in smaller subsets. You can also use getRegion()
for statistical outputs without reducing the entire collection.
Is it possible to apply a custom reducer?
Yes, you can define a custom reducer by creating a function that calculates specific metrics (e.g., variance, standard deviation). Use ee.Reducer.custom()
for this purpose.
How do I export the reduced image?
Use Export.image.toDrive()
or Export.image.toCloudStorage()
after applying reduction. Ensure the output image uses the correct projection and scale for further analysis.