Is there a way to calculate the opposite of what the qualityMosaic() does to an ImageCollection? That is to minimize a selected column (for example an added layer "ndvi") but keep the rest of the original bands associated with that ndvi (all from the same DATE). Input= ImageCollection, Output= Single Image.

1 Answer 1


If I understand correctly, you want to apply the same algorithm as qualityMosaic() except to pick the image with the smallest "quality" value instead of the largest.

In that case, all you need to do is negate the value. For example, the quality mosaic example script (which doesn't use the built-in algorithm but works the same way) adds the quality band to the collection like this:

var withNd = l7.map(function(image) {
  return image.normalizedDifference(['B4', 'B3']).addBands(image);

If I change that to

var withNd = l7.map(function(image) {
  return image.normalizedDifference(['B4', 'B3']).multiply(-1).addBands(image);

then I get cloudy pixels instead of green pixels.

If you want to do further processing with the quality value without it being negated, you could negate it again, or you could add a band for the qualityMosaic to use that is separate from the quality band.

Here's a runnable example of setting up both versions, modified from the Quality Mosaic example script:

var l7 = ee.ImageCollection('LANDSAT/LE07/C01/T1')
    .filterDate('2000-01-01', '2001-01-01');

var withNd = l7.map(function(image) {
  var nd = image.normalizedDifference(['B4', 'B3']);
  return image

function addQualityMosaicLayer(qualityBandName) {
  var greenest = withNd.qualityMosaic(qualityBandName);
  var rgb = greenest.select(['B3', 'B2', 'B1']);
  Map.addLayer(rgb, {gain: [1.4, 1.4, 1.1]}, 'Using ' + qualityBandName);

Map.setCenter(-90.08789, 16.38339, 11);


In this script the nd band of greenest is the normalized difference value, whether or not the negated value was used to make the mosaic.

  • Thanks for the solution. By the way, interesting function "addQualityMosaicLayer()" Jun 27, 2019 at 18:02
  • @AlfonsodeLara Even for a quick demo or experiment, it's handy to define functions for repeated sections, because it means you can try changing both things in parallel without having to write the change twice.
    – Kevin Reid
    Jun 27, 2019 at 21:33

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.