I have created a script of sentinel-2 images from 2017 oct to 2018 april with 20% cloud-cover at 15-days time interval. I have one imagecollection every 15 days, i also calculated NDVI and added that as a band for the first 15-days collection.

Now, every collection has a number of images with specific NDVI values. What i want to do is to compare pixel by pixel NDVI values every image within the collection and choose the pixel with highest NDVI value and print down which image among all the images is giving the highest NDVI and choose the reflectance values corresponding to that pixel and that image within that imagecollection, this way create a 15-day maximum reflectance composite derived from the maximum NDVI value-showing image inside an imagecollection. So, my aim is to get maximum reflectances of images within imagecollection for each pixel. I want to do that for every 15-days collection.

I am very much new to coding but i am in my thesis now and stuck at this point. Can anybody tell me how do i do this in GGE? I am mentioning the first 15-days code here-

var tanguarhaor = ee.Geometry.Polygon([
  [[90.9952, 25.16], [91.2616,25.1824],[91.4841,25.1053],[91.55, 24.9647], [91.4594, 24.8065], [90.8772, 24.814],[90.781,24.9635],[90.8043,25.1103],[90.9952,25.16]]


Map.addLayer(tanguarhaor, {color: 'FF0000'}, 'geodesic polygon');

function maskS2clouds(image) {
   var qa = image.select('QA60');
    var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;
   var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(
              return image.updateMask(mask).divide(10000)}

var start = ee.Date('2017-10-01');

var finish =ee.Date('2017-10-15');

var TahirpurOCT17first = ee.ImageCollection('COPERNICUS/S2')





var IMAGE1 = TahirpurOCT17second.map(function(image) { return image.clip(tanguarhaor); });

var addNDVI = function(image){var ndvi=image.normalizedDifference(['B8','B4']).rename('NDVI');return image.addBands(ndvi);};

var ndvi1 = IMAGE1.map(addNDVI);

var ndvi2 = ndvi1.sort('system:time_start', false);

var collection = ndvi2.select(['NDVI']);


I am stuck at the point how do i know from which image the maximum NDVI value is coming from within the imagecollection 'collection' in the script for each pixel and get the reflectance values corresponding to that pixel of that image within that 15-day imagecollection? Is it possible to get the result as a map somehow?


What you want is collection.qualityMosaic. See https://developers.google.com/earth-engine/ic_composite_mosaic

// This function masks clouds in Landsat 8 imagery and adds an NDVI band.
var prepareImage = function(image) {
  var score = ee.Algorithms.Landsat.simpleCloudScore(image);
  image = image.updateMask(score.select(['cloud']).lt(20));
  var ndvi = image.normalizedDifference(['B5', 'B4']).rename('ndvi')
  return image.addBands(ndvi)

// Load a 2014 Landsat 8 ImageCollection.
// Map the cloud masking and quality band function over the collection.
var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
  .filterDate('2014-06-01', '2014-12-31')

// Create a cloud-free, most recent value composite.
var greenestPixelComposite = collection.qualityMosaic('ndvi');

Map.addLayer(greenestPixelComposite, vizParams, 'greenest pixel composite');

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.