I have a Landsat image collection with, additional to the usual bands, the NDWI index (used for water) for each image in that collection.

I would like to create two subsets of this image collection:

  1. one with the upper 25 percent of NDWI index values (75 - 100);
  2. another one with the lower 25 percent of the NDWI index values (0 - 25);

So the result would be three separate image collections (containing all bands). First one containing all images. The second one containing all images selected by the upper 25% NDWI index values. The third one containing all images selected by the lowest 25% NDWI index values.

Please find a toy script at this link: https://code.earthengine.google.com/4bc201244078d5849d033bb7560a3479.

Please note that in that script there is also a quality mosaic. However, I am not satisfied by the quality mosaic because it tends to pick up the extremes. Therefore I would like to work with the lower and upper 25 percent.

1 Answer 1


I guess you are looking for reducing the image collection with percentiles. You could either use the percentiles or use interval mean to get the mean of values in a percentile range. Most of the times, the reducer percentile with percentiles between 20-40 works best, as cloud are in the ~ upper 60-100% and shadows in the lower ~0-10% of the image collection pixel values. You will see that in the outcome of the reducer 25 and 75:

// get the original bandNames
var bandNames = l8withNDWI.first().bandNames();

// Use reducer percentiles to get the 25 and 75 
var upper75 = l8withNDWI.reduce(ee.Reducer.percentile([75])).rename(bandNames);
var lower25 = l8withNDWI.reduce(ee.Reducer.percentile([25])).rename(bandNames);

// Or use reduce intervalMean to get the mean of all values between 0-25 or 75-100
var intervalMean0_25 = l8withNDWI.reduce(ee.Reducer.intervalMean(0, 25)).rename(bandNames);
var intervalMean75_100 = l8withNDWI.reduce(ee.Reducer.intervalMean(75, 100)).rename(bandNames);

If you want to slice all the pixel values between percentile 0 and 25, you will need to coop with imageCollection.toArray() and slice out the lower and higher values. But I guess you are looking for a way to make simple and fast composites. That will succeed using these reducer.

Link code

  • Thank you for your useful comment; the code is working properly. However, I'm afraid I'll have to do it with imageCollection.toArray() because I want to calculate the standard statistics (by applying a combined reducer) over both subsets. I want to use the NDWI index as a criterium to dive the collection into two subcollections. Then I would like to calculate descriptive statistics (intv mean, median etc. etc.) by applying a combined reducer.
    – sir_olf
    Commented May 13, 2019 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.