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});

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});


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

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

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

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.