1

I want to mask all pixels above a threshold in a multiband image. If any band is over threshold, that pixel is masked. I can do this using .and to apply logic to each band, but is there a less verbose way to accomplish this? Not a big deal for a the three band image example below, but cumbersome to type for an image with many bands.

var thresh = 5000
var image = ee.Image('COPERNICUS/S2_SR/20170328T083601_20170328T084228_T35RNK')
var maskImage = image.select(['B2','B3','B4']).lt(thresh) // 3 band image, each band has value of 1 or 0

// using `.and` to ensure all bands below threshold 
var masterMask = maskImage.select('B2')
  .and(maskImage.select('B3'))
  .and(maskImage.select('B4')) 
  .rename('masterMask')

https://code.earthengine.google.com/?scriptPath=users%2Fcaseyengstrom%2Freprex%3Amultiband_mask

1 Answer 1

2

You can reduce using a max reducer to find pixels where any band meets the criteria.

var mask = image.select(['B2','B3','B4']).gt(thresh).reduce(ee.Reducer.max())

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.