leccmo
leccmo

Reputation: 379

How to reduce an image collection by numbers matching conditions in Google Earth Engine

Is there way to reduce an image collection by numbers how many images matching conditions?

For example, I want to create a new image to visualize how many days meet some conditions in a period.

ref image

Upvotes: 0

Views: 654

Answers (1)

Kevin Reid
Kevin Reid

Reputation: 43902

When you want to convert an image collection to an image by combining all the pixels in some way for each spatial location, the solution is ImageCollection.reduce. In this case, we can use the ee.Reducer.count reducer to count the number of pixels meeting the condition.

JavaScript example:

var daysMeetingConditionImage = imageCollectionOfDayImages
  .map(function (image) {
    // Apply the condition, whatever it is, as a mask.
    // Masked-off pixels will not be counted.
    return image.updateMask(
       image.select('B2').gt(7)  // Change this to whatever your per-pixel condition is
    );
  })
  .reduce(ee.Reducer.count());

Upvotes: 1

Related Questions