ImageCollection Reductions

Consider the example of needing to take the median over a time series of images represented by an ImageCollection. To reduce an ImageCollection, use imageCollection.reduce(). This reduces the collection of images to an individual image as illustrated in Figure 1. Specifically, the output is computed pixel-wise, such that each pixel in the output is composed of the median value of all the images in the collection at that location. To get other statistics, such as mean, sum, variance, an arbitrary percentile, etc., the appropriate reducer should be selected and applied. (See the Docs tab in the Code Editor for a list of all the reducers currently available). For basic statistics like min, max, mean, etc., ImageCollection has shortcut methods like min(), max(), mean(), etc. They function in exactly the same way as calling reduce(), except the resultant band names will not have the name of the reducer appended.

imageCollection.reduce diagram
Figure 1. Illustration of an ee.Reducer applied to an ImageCollection.

For an example of reducing an ImageCollection, consider a collection of Landsat 5 images, filtered by path and row. The following code uses reduce() to reduce the collection to one Image (here a median reducer is used simply for illustrative purposes):

// Load an image collection, filtered so it's not too much data.
var collection = ee.ImageCollection('LT5_L1T')
  .filterDate('2008-01-01', '2008-12-31')
  .filter(ee.Filter.eq('WRS_PATH', 44))
  .filter(ee.Filter.eq('WRS_ROW', 34));

// Compute the median in each band, each pixel.
// Band names are B1_median, B2_median, etc.
var median = collection.reduce(ee.Reducer.median());

// The output is an Image.  Add it to the map.
Map.setCenter(-122.3355, 37.7924, 9);
Map.addLayer(median, {bands: ['B4_median', 'B3_median', 'B2_median'], gamma: 1.6});

This returns a multi-band Image, each pixel of which is the median of all unmasked pixels in the ImageCollection at that pixel location. Specifically, the reducer has been repeated for each band of the input imagery. Note that the band names have the name of the reducer appended: ‘B1_median’, ‘B2_median’, etc. The output should look something like Figure 2.

ImageCollection.reduce output
Figure 2. A false color composite of the median of Landsat 5 scenes in 2008.

For more information about reducing image collections, see the reducing section of the ImageCollection docs.

Send feedback about...

Google Earth Engine API