0

What is the FASTEST way to calculate the min and max of one band of an ee.Image?

I have tried using ee.reduceRegions in the following code, but it adds seconds to my processes. I am using this in a custom Angular application and need to make frequent calls to this method - speed is critical!

Is it possible to just use ee.reduce()? This seems to return an image not a number...

// Private method to add min, max, and mean stats to the properties of any image
exports._add_stats_to_image = function(projectionResult) {
  // try adding the image stats as metadata before returning the image
    var reducers = ee.Reducer.mean().combine({
      reducer2: ee.Reducer.minMax(),
      sharedInputs: true
  });
    
    var stats = projectionResult
              .select("b1") // band is now labelled "b1" for all single band image results
              .reduceRegion({
                  reducer : reducers,
                  // geometry: geom,
                  bestEffort: true,
                  crs: "EPSG:4326",
                  scale: ee.Number(100),
                  maxPixels: ee.Number(1e9),
              });
  return projectionResult
          // .clip(geom)
          .set("mean", stats.get("b1_mean"))
          .set("min", stats.get("b1_min"))
          .set("max", stats.get("b1_max"));

}

1 Answer 1

0

I assume you mean ee.Image.reduce() and ee.Image.reduceRegion(). ee.Image.reduce() reduces a multiple bands in an image into a single band. For your case, ee.Image.reduceRegion() is the way to go. It can be a slow operation, since it need to read every single pixel value in your region at the scale you specified.

The way to speed it up is to minimize the number of pixels read. If you don't need exact results, you can get an approximation by increasing the scale. When I need to increase the performance, I normally set scale to the native scale if the imagery, set bestEffort to true, and set maxPixels to a values giving me good enough performance. EE will then dynamically pick a scale where it can perform the reduction with the provided number of pixels. Of course, with this approach, the larger the area, the less accurate the result.

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.