0

How is ee.Reducer.count() counting non-fully covered pixels (and likewise, for ee.Reducer.histogram()) ?

It seems there is an implicit minimum cell coverage, with pixels having only a small part inside the geometry being counted as 0? Is this correct, and what is the minimum threshold used? Did I miss something in the documentation?

Example below shows a simple geometry, that covers 3 pixels, at 27%, 49% and 74%:

  • ee.Reducer.count() indicates only two pixels.
  • ee.Reducer.histogram().unweighted() counts likewise only two, and seems to discard the pixel with only 27% coverage.

Link to code: https://code.earthengine.google.com/14fafad3401721f5ef33543015b539ca

enter image description here

//////////////////
// import 
///////////////// 

var rectangle = ee.Geometry.Polygon(
        [[[-92.538634, 40.186573], [-92.538634, 40.186389], [-92.537857, 40.186389],
          [-92.537857, 40.186573]]], null, false);
var CDL_2015 = ee.Image('USDA/NASS/CDL/2018')
  .select('cropland')


//////////////////
// Visu
/////////////////


// show
Map.centerObject(rectangle)
Map.addLayer(CDL_2015.clip(rectangle.buffer(10)), {}, "CDL_2015")
Map.addLayer(ee.FeatureCollection(rectangle).style({width: 3, color: "blue", fillColor: "#00000000"}), {}, "CLU_here")


// get count


var count_W = CDL_2015.reduceRegion({
      geometry: rectangle,
      reducer: ee.Reducer.count(), scale: 30});    

var count_noW = CDL_2015.reduceRegion({
      geometry: rectangle,
      reducer: ee.Reducer.count().unweighted(), scale: 30});    
var hist_W = CDL_2015.reduceRegion({
      geometry: rectangle,
      reducer: ee.Reducer.histogram(), scale: 30});
var hist_noW = CDL_2015.reduceRegion({
      geometry: rectangle,
      reducer: ee.Reducer.histogram().unweighted(), scale: 30});

print(count_W.get("cropland"), "Number pixels: (weighted)")
print(count_noW.get("cropland"), "Number pixels: unweighted?")

print(ee.Dictionary(hist_W.get("cropland")).get("histogram"), "histogram: (weighted)")
print(ee.Dictionary(hist_noW.get("cropland")).get("histogram"), "histogram: unweighted?")
1

With unweighted reducers (e.g. count) pixels are included if their centroid is in the region.

See https://developers.google.com/earth-engine/reducers_reduce_region#pixels-in-the-region

| improve this answer | |
  • perfect, thanks! – Matifou Aug 11 '19 at 21:40

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.