I'm working with the MODIS Terra Continuous Fields 250m product. The data include several bands, including a "Quality" band.

var geometry = ee.FeatureCollection("FAO/GAUL/2015/level0")
.filter(ee.Filter.eq("ADM0_NAME", "Rwanda"));

var data = ee.ImageCollection('MODIS/006/MOD44B')
.map(function(image){return image.clip(geometry)});

var quality00 = data.filter(ee.Filter.date('2000-01-01', '2000-12-31'))

The quality band is an 8-bit image, and the quality assessment is based on the raw imagery being cloudy, high aerosol, cloud shadow, or view zenith greater than 45 degrees. MODIS recommends masking out any images in which the quality was bad "for 2 or more of the 8 time periods".

The MODIS documentation describes the bits as follows: from their documentation I suspect these are the 8 underlying images being quality-assessed, but I am not sure.

  • Bit 0: State of input layers DOY 065-097: 0: Clear, 1: Bad
  • Bit 1: State of input layers DOY 113-145: 0: Clear, 1: Bad
  • Bit 2: State of input layers DOY 161-193: 0: Clear, 1: Bad
  • Bit 3: State of input layers DOY 209-241: 0: Clear, 1: Bad
  • Bit 4: State of input layers DOY 257-289: 0: Clear, 1: Bad
  • Bit 5: State of input layers DOY 305-337: 0: Clear, 1: Bad
  • Bit 6: State of input layers DOY 353-017: 0: Clear, 1: Bad
  • Bit 7: State of input layers DOY 033-045: 0: Clear, 1: Bad

I'm not sure how to take this layer to identify the pixels with low quality in a given year. If the values were numeric (out of 8) then I would expect that any value greater than 2 gets flagged. But that's not how the data are organized: the minimum value of the quality band is 0 and the maximum is 255.

How do you use this 8-bit image to identify low quality pixels?

UPDATE: I've found some user support to help me figure out the binary data structure. This tutorial was very useful. The one thing I still am trying to figure out: how do I make an image where each grid-cell reports the count of bits that were 1? For example, if the binary code is 01001100, then the value for that grid-cell should be 3. How do I do this?

1 Answer 1


ee.Image.bitCount counts the number of bits set in each pixel.

var count = image.bitCount()
  • Thank you for offering a tip! I just tried this using the quality00 variable, but the output still has a maximum value of 255 instead of 8. Is there something I may have done wrong?
    – user157564
    Aug 10, 2023 at 0:29
  • Ah, maybe the image stores the former image's properties? I just rendered a histogram and the maximum value in the variable count is 8. Finally cracked it! Thank you so much!!
    – user157564
    Aug 10, 2023 at 0:38

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.