0

I'm trying to do ndvi reclassify in google earth engine. I know exactly how to do it in Arcgis but I'm very new with GEE and I got stuck with javascript. What I want to do is to use mean + standard deviation of ndvi as a threshold. Pixel value between -1 to mean +SD reclassify to 0 and pixel between mean +SD to 1 reclassify to 1. The two classes can be displayed into different colour as a same layer, but ideally I would like to have the "0" area with no colour so I can check how well the "1" area overlaps with vegetation. Here's the code I have worked out so far:

var Blueskin =ee.Image('COPERNICUS/S2/20160721T223713_20160722T000334_T59GMK');
Map.centerObject(Blueskin, 10);
var Color = {bands:['B8','B4','B3'], max: 3000} 
var Mask = ee.FeatureCollection(table);
Mask = Mask.geometry();
Map.centerObject(Mask);
var Blueskin = Blueskin.clip(Mask);
var ndvi = Blueskin.normalizedDifference(['B8', 'B4']);
var palette = ['blue', 'white', 'green'];
var ndviParams = {min: -1, max: 1, palette: palette};
Map.addLayer(ndvi, ndviParams, 'NDVI image');

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

// Use the combined reducer to get the mean and SD of the image.
var stats = ndvi.reduceRegion({
  reducer: reducers,
  bestEffort: true,
});

// Display the dictionary of band means and SDs.
print(stats);

The aoi is the estuary in the image. I can get the value of mean and SD so I can actually manually set the threshold. But I don't know the code to set the threshold, reclassify pixels with the value lie between the same interval to a same integer (0 or 1) and give each area a colour.

1 Answer 1

0

There is about a dozen ways to approach this; you could apply clamp, a reducer or simple binary logic:

// Get your mean and std
var mean = ee.Number(stats.get('nd_mean'))
var std = ee.Number(stats.get('nd_stdDev'))
// Apply your ranges and turn into binary image indicating 1 between your defined ranges
var maskImage = ndvi.updateMask(ndvi.lt(mean.add(std))).updateMask(ndvi.gt(mean.subtract(std))).unmask().gt(0)
Map.addLayer(maskImage, {}, 'mask image')
3
  • Hi @Jobbo90, thanks very much for your answer. I have tried your code and I don't think"var maskImage = ndvi.updateMask(ndvi.lt(mean.add(std))).updateMask(ndvi.gt(mean.subtract(std))).unmask().gt(0)" works as what I expected. I meant to use NDVI mean +1SD as a minimum threshold for reclassification, above the threshold to value 1 reclassify as 1 and below the threshold to value -1 reclassify as 0. I changed a bit of the code to "var maskImage = ndvi.updateMask(ndvi.gt(mean.add(std)));" and it worked as what I expected.
    – Rose Chai
    Commented Jan 12, 2020 at 22:39
  • Hi @Jobbo90, sorry for me having so many simple questions about GEE I'm still really new and trying to learn javascript from scratch. After I made change of that code I can see the black colour regions overlap with the vegetation area in the estuary, but I do notice the coloured regions are not universally black, which means I failed to reclassify the pixel value between ndvi mean+ 1SD to 1 to 1. How can I do reclassification correctly? Thanks.
    – Rose Chai
    Commented Jan 13, 2020 at 2:49
  • Hi, I have solved this problem but I have some new issue. If you are interested please check (gis.stackexchange.com/questions/347335/…). Thanks
    – Rose Chai
    Commented Jan 14, 2020 at 2:39

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.