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
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.