I am looking for a way to know how many images I have in a specific time frame. (I will later want to have all of their indexes and dates written in a list, so I can address them later on).

I have filtered the ImageCollection to 1 month, which should give me approx. 6 images for Sentinel-2 (revisit time should be 5 days), but I get a ridiculously high number. Also, I am not able to extract the dates as I need (first and last date of the collection).

var ndvi_s2 = ee.ImageCollection('COPERNICUS/S2_SR')
  .filterDate('2019-01-01', '2019-02-01')
  .map(function (image) {
    return image
      .normalizedDifference(['B8', 'B4'])

// Limit the collection to the 10 most recent images.
var recent = ndvi_s2.sort('system:time_start', false).limit(5);
print('Recent images: ', recent);

// Get the number of images.
var count = ndvi_s2.size();
print('Count ALL: ', count);
var count = recent.size();
print('Count recent: ', count);

// Get the date range of images in the collection.
var range = recent.reduceColumns(ee.Reducer.minMax(), ["system:time_start"])
print('Date range: ', ee.Date(range.get('min')), ee.Date(range.get('max')))

// Sort by a cloud cover property, get the least cloudy image.
var image = ee.Image(recent.sort('CLOUD_COVER').first());
print('Least cloudy image: ', image, ' Cloud Cover: ', image.get('CLOUD_COVER'));

These are the results:

enter image description here

Any ideas? Why do the "ALL" numbers is so big? And why can't I get the dates?

By the way - is there a way of seeing the NDVI values for the images I have printed out? I mean - see it in the console.

1 Answer 1


Your are counting the number of images you have in your collection. You filtered the collection down to one month worth of data, but haven't filtered based on bounds. So the count you're seeing is how many Sentinel 2 images there are, globally, in that month. You're clipping each image to your region of interest. That will not remove them from the collection, just update the image masks. You probably want to add a .filterBounds(region) in there.

Now, if your region intersects more than one of the Sentinel 2 tiles, you'll get more than 5 images.

  • Thank you Daniel. Understood. Any ideas why I get an error on the dates prints? Apr 25, 2020 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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