# Google Earth Engine: Getting Range of Image's Values

I'm trying to find the maximum and minimum of a Sentinel-2 image that I have done band calculations on. My current code is:

``````//adding a single sentinel 2 image to map
var img161 =ee.Image('COPERNICUS/S2/20160718T165316_20160718T215633_T16UEG');

//evi visual parameters
var evivisparam = {min: -1, max: 1};

//evi calculation of img161
var evi = img161.expression(
'2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {
'NIR': img161.select('B8'),
'RED': img161.select('B4'),
'BLUE': img161.select('B2')
});
``````

I would like to find the pixels with the highest and lowest values. How can I do this?

• Have you tried .reduceRegion(ee.Reducer.min()) Commented Nov 10, 2021 at 12:37

Your code have several issues. First of all, you need to adequately scale image bands for obtaining EVI values between -1, 1. For Sentinel 2 products scale is 10000. You also need a region where to retrieve min and max values. It is convenient to rename evi obtained image as 'evi' band. Following code can do that.

``````var geometry = ee.Geometry.Polygon(
[[[-86.40440229458056, 55.396064195727114],
[-86.40440229458056, 55.385144194755334],
[-86.37556318325244, 55.385144194755334],
[-86.37556318325244, 55.396064195727114]]], null, false);

//adding a single sentinel 2 image to map
var img161 = ee.Image('COPERNICUS/S2/20160718T165316_20160718T215633_T16UEG')
.divide(10000);

//evi visual parameters
var evivisparam = {min: -0.1746, max: 0.7939};

//evi calculation of img161
var evi = img161.expression(
'2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {
'NIR': img161.select('B8'),
'RED': img161.select('B4'),
'BLUE': img161.select('B2')
}).rename('evi');

var reducers = ee.Reducer.min().combine({
reducer2: ee.Reducer.max(),
sharedInputs: true
});

var stats_values = evi.select('evi').reduceRegion(reducers, geometry);

Map.centerObject(geometry);

print("evi_min", stats_values.get('evi_min'));
print("evi_max", stats_values.get('evi_max'));
``````

After running it in GEE code editor I got both min and max values for evi in Console Tab.

Use the numInputs option on the minMax reducer to also reduce a lon/lat image at the same time. Combine min and max so you only have to make 1 pass.

``````var reducer = ee.Reducer.min(3).combine(ee.Reducer.max(3), null, true)
reducer: reducer,
geometry: img161.geometry(),
scale: 10,
maxPixels: 1e9
})
``````