1

I am using GEE and wish to set a threshold and exclude images based on an the image's band value and remove it from a collection. I do not want to mask the image, I want it physically out of the collection. As far as I can tell using ee.filter only works with metadata, not the images' bands.

Anyone have a clue?

  • Can you give an example of the process you're currently using to attempt this? If other users can see your code, they'll be much better able to spot where you might be going wrong. Also, please take the tour if you haven't already, as it will give you an overview of the Q&A model we follow here. When a question is asked, it is expected that the asker has already put considerable effort into solving it themselves. It's not exactly the place to start your research. – JoshC Mar 22 '18 at 16:13
  • Your question is not clear. An Image can be made out of million pixels, you'd have to use a Reducer over the image and assign the result to your image's metadata – Rodrigo E. Principe Mar 22 '18 at 17:48
3

This can be done in two steps. First, you need to turn information stored in images into metadata (image property). Then it can be used in the same way as all other filters. For example, this is how you can filter all images with some number of potential water pixels within some distance from a given point: https://code.earthengine.google.com/491ecb33a4b5fbe5f4cb9a3669254d05

// get all images for a given geometry
images = images.filterBounds(geometry)
print('Number of images: ', images.size())

// estimate potential water probability using MNDWI
var water = images.map(function(i) {
  var water = i.divide(10000).normalizedDifference(['B3', 'B8']).unitScale(-0.05, 0.15)

  return water.mask(water)
})

// estimate number of pixels above some thredhold within 500 m buffer around given point

// define area of interest and scale
var aoi = geometry.buffer(500)
Map.addLayer(aoi)

var scale = Map.getScale()

// applies thresholds and computes new property to be used for filtering
function threshold(i) {
  var count = i.gt(0.5).reduceRegion(ee.Reducer.sum(), aoi, scale).values().get(0)

  return i.set({water_pixel_count: count})
}

water = water.map(threshold)

print('Number of water pixels for all images:', water.aggregate_array('water_pixel_count'))

// filter
water = water.filter(ee.Filter.gt('water_pixel_count', 100))

print('Number if images after filtering: ', water.size())

require('users/gena/packages:animation').animate(water)

The above code computes a new property for every image and then uses that property to filter image collection, resulting in only images where water is present.

enter image description here

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.