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

Link: https://code.earthengine.google.com/1fe1753f49d5ebbbb7aa4d86040e839c

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);
function NDVI(image) {
  return image.addBands(image.normalizedDifference(["B5", "B4"]).rename("NDVI"));

function NDWI(image) {
  return image.addBands(
    image.normalizedDifference(["B3", "B5"])
function NDBI(image) {
  return image.addBands(
    image.normalizedDifference(["B6", "B5"])

function DIFF(image){
  return image.addBands(ee.Image.cat([image.select("NDVI_max").subtract(image.select("NDVI_min")).rename("NDVI_diff"),
function EVI(image){
  return image.addBands(image.expression(

var l8Col = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
              .filterDate("2018-1-1", "2020-10-13")
              .filter(ee.Filter.lte("CLOUD_COVER", 50))

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"]);
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"]);

var maxmin = min.addBands(max1);
var maxmin1 = maxmin.map(DIFF);

1 Answer 1


If you want the difference you can subtract the two images (max and min) right away. This would work:

var diff = max1.subtract(min);
print(diff,"diff, max min");

However be aware that the bands won't be renamed like this.

  • Thankyou for sovling my problem! I got the result according to your sugestion! Oct 15, 2020 at 1:40
  • In this case you can hit the check mark next to my answer to mark your question as solved
    – JonasV
    Oct 15, 2020 at 7:51

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.