How to get the reflectance images in red band and near-infrared band respectively corresponding with the max NDVI that I calculate from the reflectance image collection in their red bands and near-infrared bands? The following code shows how I get the image of max ndvi.

var collection = ee.ImageCollection('LANDSAT/LE07/C01/T2_SR')
    .filterDate('2016-05-01', '2016-9-30')
    .filterBounds(fc);   // fc is the polygon of study area. 
// A function to compute NDVI.
var NDVI = function(image) {
  return image.expression('float(b("B4") - b("B3")) / (b("B4") + b("B3"))');
};   //B4 is the reflectance in the near-infared band, and B3 is the reflectance in the red band.

// Reduce the collection by taking the max.
var max_ndvi = collection.map(NDVI).max();


1 Answer 1


You can use the function qualityMosaic for that. It will return the maximum value for the specified band ('NDVI' in your case), and return the corresponding other band values to that maximum NDVI value.

// quality mosaic based on the NDVI band
var qualMosaic = collection.map(NDVI).qualityMosaic('NDVI')
      // eventually select only the asked bands
      .select(['B3', 'B4', 'NDVI'])

Besides, some other improvements:

1) you are using the Tier 2 collection of Landsat 7, probably you are interested in the Tier 1 collection LANDSAT/LE07/C01/T1_SR (at least, there are no images in the temporal and spatial range you specify in Tier 2).

2) Make sure you add the NDVI band to the image, while remaining the other bands, and properly rename it so you can easily select the NDVI band later.

var NDVI = function(image) {
  return image.addBands(image.expression(
        'float(b("B4") - b("B3")) / (b("B4") + b("B3"))').rename('NDVI'));

See link full code

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.