Search code examples
javascriptimagegoogle-earth-engine

Google earth Image: Create an upper and lower quartile composite image from an image collection


I am trying to create a composite image from an image collection (In this example Sentinel 2) where the pixel value for the resulting composite is the lower or upper quartiles of the pixel value distribution.

Its easy to get the mean, median, maximum and minimum pixel values but I don't know how to make a composite of lower quartile values.

// In this code I created a collection where all the clouds had been removed
// I then mapped the NDVI values to the entire Collection.
// I want to create a composite image of the lower quartile NDVI values

var withNDVI = col_noclouds.map(addNDVI);

// Get the max, min and median values in each band.
var maximum = withNDVI.max();
var minimum = withNDVI.min();
var median = withNDVI.median();


// Display the composite.
Map.addLayer(maximum, ndviParams_Col, 'maximum_NDVI');
Map.addLayer(median, ndviParams_Col, 'median_NDVI');
Map.addLayer(minimum, ndviParams_Col, 'minimum_NDVI');

If anyone can suggest a way to create a composite of lower quartile pixel values that would be very useful.


Solution

  • So a nice person answered this for me so I thought I would post it here:

    You can use ee.ImageCollection.reduce() and ee.Reducer.percentile() to create a lower quartile composite. For example:

    Map.addLayer(
    withNDVI.reduce(ee.Reducer.percentile([25])),
    {bands:'NDVI_p25', min:-1, max:1},
    '25 percentile NDVI'
    );