I would like to know how to count the number of unmasked pixels in a single geometry point i.e. how many images have not been masked at that location.
The following code counts all images, both masked and unmasked at the point of interest, I would like to know the number for each.

//specifies the start and end date
var start_time = ee.Date('2001-01-01');
var end_time = ee.Date('2010-01-01');

//specifies area of interest
var poi = ee.Geometry.Point([1.1370849609375,52.20171539256484]);

//filters landsat 5 collection to date and roi
var landsat5 = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
.filterDate(start_time, end_time);

//creates a cloud mask
var cloud_func = function(img){ 
  return img.updateMask(img.select(['pixel_qa']).bitwiseAnd(2).neq(0));  

//applies the mask
var masked_collection = landsat5.map(cloud_func);

//prints the total number of landsat images 
var number_of_landsats = ee.Number(masked_collection.size());
print(number_of_landsats, 'number');

1 Answer 1


You can create an image counting all unmasked pixels and then use reduceRegion to count only the unmasked pixels at your POI.

// creates an image with the number of unmasked pixels
var number_unmasked_pixels = masked_collection.select("B1").count()

// count pixels at poi
var unmasked_pixels_poi = number_unmasked_pixels.reduceRegion(ee.Reducer.first(), poi, 30)

print(unmasked_pixels_poi, "unmasked pixels in POI")

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.