0

I am working with Google earth Engine and I am trying to extract/Filter (clip) pixels in a band using another image (band). I calculated NDVI and created a threshold value that rendered an image with NDVI > 0.3 but I wanted to extract the corresponding pixels in the visible an NIR bands.
Here is snippet code.

var s2 = ee.ImageCollection('COPERNICUS/S2');
var s2_filtered = s2.filterDate('2017-01-01', '2017-12-31')
                  .filterBounds(geometry) //custom Geometry

var calcNDVI = function(x){
  var ndvi4 = x.normalizedDifference(["B5", "B4"]).rename("ndvi")
  return x.addBands(ndvi)
}

var ndviCollection = s2_filtered.map(calcNDVI)
var maxNDVI = mosaic.select("ndvi");
var threshold = maxNDVI.gt(0.3)

I am at the point where I wanted to clip the corresponding pixels in "B", "G", "R" and "NIR" bands using the threshold variable(image). Obviously, I'm stuck here. Please let me know if there is with a way to filter/clip pixels of one band using another band with in GEE. The task is similar to using Clipper in QGIS which is the options I am left with if this doesn't work.

Thanks for your help!

Rodrigo E. Principe
  • 1,281
  • 16
  • 26
Destaneon
  • 55
  • 1
  • 6

1 Answers1

0

The variable threshold is a mask, so you have to mask out pixels in the mosaic using the threshold mask, right? If that is the case, simply update the mask of the image:

var masked = maxNDVI.updateMask(threshold)
Rodrigo E. Principe
  • 1,281
  • 16
  • 26
  • Thanks! I that was very helpful. I used this variable (masked) to mask out the bands in the mosaic image just like I wanted them. – Destaneon Mar 17 '18 at 00:55