I'm using Google Earth Engine's Javascript API to process Sentinel-2 images from 2016-2021. I've calculated the EVI values for these images, which has a range of -1 to 1. I want to correct any anomalous pixels that fall outside of their range by enforcing -1 as the minimum value possible and 1 as the maximum possible value. Is there a way to enforce these maximum and minimum values?

1 Answer 1


Use .clamp() for that. This will set all values above or below a certain threshold to the threshold you supply to the function. Here's a minimum example:

// Test Image with Values between -1.5 to 1.5
var test = ee.Image.random().multiply(3).subtract(1.5)

var clamped = test.clamp(-1, 1)

Map.addLayer(test, {}, "Values outside -1, 1")
Map.addLayer(clamped, {}, "All values inside -1, 1")

Alternatively you can also think about masking values outside of your accepted range.

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.