[GIS] Google Engine – Make a greenest pixel composite for Sentinel 2

google-earth-enginendvisentinel-2

Does anyone know how to do a composite of greenest pixel for Sentinel 2?

That is calculate the maximum NDVI for a Image collection, and then do a pixel-wise image stacking of the original bands (that correspond to the image of the maximum NDVI).
There is already an algorithm for Landsat 8 named .qualityMosaic() , but it needs the quality band that is only available for Landsat.

Best Answer

You can use qualityMosiac exactly similar for Sentinel-2 as for Landsat. The method you are looking for is described here. What you need is adding a NDVI band to the image collection of Sentinel-2 and use qualityMosaic('NDVI') to obtain the per pixel values of the corresponding pixel with the highest NDVI value.

var s2 = ee.ImageCollection("COPERNICUS/S2")
.filterBounds(ee.Geometry.Point([121.331, 39.1426]))
.filterDate('2018', '2019');

// compute ndvi and add to the image collection
var withNDVI = s2.map(function(img){
  var red = ee.Image(img.select('B4'));
  var nir = ee.Image(img.select('B8'));
  var ndvi = (nir.subtract(red)).divide(nir.add(red)).rename('ndvi');
  return img.addBands(ndvi);
});

// use quality mosaic to get the per pixel maximum NDVI values and corresponding bands
var ndviQual = withNDVI.qualityMosaic('ndvi');
print(ndviQual)
Map.addLayer(ndviQual, {min:0, max: 10000, bands: ['B4', 'B3', 'B2']})

Link script