2

I try to export a raster with NDVI values from Google Earth Engine. Although the export works fine, the original NDVI values (-1 to +1) are translated into 8bit values between 0 and 255 in the resulting image. How can I export the NDVI results conserving the original values?

Below the code, I´m using. If you import the "Sentinel-2 MSI: MultiSpectral Instrument, Level-2A" image collection and set the variable name to sent2_collection, you can run the code.

function add_ndvi_band(image){
  var ndvi = image.normalizedDifference(["B8","B4"]);
  return image.addBands(ndvi);
}

var time_filter = sent2_collection.filterDate("2019-01-01", "2019-12-31");
var time_filter_ndvi = time_filter.map(add_ndvi_band);

Map.addLayer(time_filter.median(), {bands:["B4","B3","B2"], min:0, max:3000}, "Cuautla - true color");
Map.addLayer(time_filter_ndvi.median(), {bands:"nd", min: -1, max: 1}, "Cuautla-NDVI");

var exportar_mapa = time_filter_ndvi.median().visualize({bands: ['nd', 'nd', 'nd'],max: 1.0});

Export.image.toDrive({image: exportar_mapa, description: 'ndvi',  scale: 10});
1
  • After all, excuse me my bad English, I hope you can understad my doubt. When I run your script the row .. '=.var time_filter = sent2_collection.filterDate("2023-10-01", "2023-10-31");is highlighted in red and there is no export to Drive in the task. I just matched the date with the dates I am working at the rest of scripts. Can you said me where Oct 31, 2023 at 11:39

1 Answer 1

4

The purpose of the Image.visualize algorithm is to convert images to RGB in the range 0-255 for display. Remove it from your code if you want original values. Replace

var exportar_mapa = time_filter_ndvi.median().visualize({bands: ['nd', 'nd', 'nd'],max: 1.0});

with

var exportar_mapa = time_filter_ndvi.median().select(['nd']);

to selects the one band you want, but not rescale it to 8-bit values.

1
  • @Flo You need .select(['nd']) to choose the band you want to export. I updated my answer.
    – Kevin Reid
    Mar 26, 2020 at 4:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.