# Calculate the difference of max image and min image in GEE

I am preparing parameters for the RF classification model. I calculated the NDVI,NDWI,EVI,NDBI from landsat8 time series. Then I calculated the minimum image colletcion (var min) and maximum image colletion (var max1) of the time series. Both of the two image collections include NDVI,NDWI,EVI,NDBI.

I define a function (DIFF) to further calculate the difference between the maximum and minimum image collection (including the difference between maximum value and minimum value of NDVI,NDWI,NDBI,EVI), but made mistakes in the codes (telling maxmin.map is not a function).

I think there should be easier way to calculate the difference, but I am still not practiced in GEE...

``````var s2col = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filter(ee.Filter.calendarRange(2018, 2019, 'year'))
.filter(ee.Filter.calendarRange(1, 3, 'month')).filterBounds(Linzhi);

//NDVI
function NDVI(image) {
}

//NDWI
function NDWI(image) {
image.normalizedDifference(["B3", "B5"])
.rename("NDWI"));
}

//NDBI
function NDBI(image) {
image.normalizedDifference(["B6", "B5"])
.rename("NDBI"));
}

//difference
function DIFF(image){
image.select("NDWI_max").subtract(image.select("NDWI_min")).rename("NDWI_diff"),
image.select("NDBI_max").subtract(image.select("NDBI_min")).rename("NDBI_diff"),
image.select("EVI_max").subtract(image.select("EVI_min")).rename("EVI_diff")]));
}

//EVI
function EVI(image){
'2.5*(NIR-RED)/(NIR+6*RED-7.5*BLUE+10000)',{
NIR:image.select('B5'),
RED:image.select('B4'),
BLUE:image.select('B2'),
}).float().rename('EVI'));
}

var l8Col = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
.filterBounds(Linzhi)
.filterDate("2018-1-1", "2020-10-13")
.filter(ee.Filter.lte("CLOUD_COVER", 50))
.map(NDVI)
.map(NDWI)
.map(NDBI)
.map(EVI);

var min = l8Col.reduce(ee.Reducer.intervalMean(0,5)).select(["NDVI_mean","NDWI_mean","NDBI_mean","EVI_mean"],["NDVI_min","NDWI_min","NDBI_min","EVI_min"]);
print(min,"min");
var max1 = l8Col.reduce(ee.Reducer.intervalMean(95,100)).select(["NDVI_mean","NDWI_mean","NDBI_mean","EVI_mean"],["NDVI_max","NDWI_max","NDBI_max","EVI_max"]);
print(max1,"max");

var maxmin1 = maxmin.map(DIFF);
print(maxmin,"maxmin");
``````

``````var diff = max1.subtract(min);