# Why do different methods give different numbers of pixels in an image in Google Earth Engine?

I'm trying to figure out why I get different answers when calculating the total number of pixels in an image in different ways.

1. Calculate a histogram on all possible values, then add together all of the categories to get the total number of pixels. This won't count NA's.
2. Use the `ee.Reducer.count()` function. This also doesn't count NA's, so I would expect this to give the same answer as number 1.
3. Use `unmask().ee.Reducer.count()` function. This DOES count NA's, so it will be larger than number 2 if there are NA's.
4. print the image, look at the dimensions, and multiply the 2 dimensions to get the number of pixels. This should count NA's and I would expect it to give the same answer as number 3.

Why do these methods give different counts of the total number of pixels in an image?

I don't have all the details to explain all of the differences you are seeing, but I can say that (1) is substantially different from (2) and (3) because the `reduceRegion` call for (1) has a `scale` specified and the other two do not. I don't recall exactly how the default scale is determined, to compare the (2) and (3) cases with (4). But the documentation does say that it's a good idea to always explicitly specify a scale. Once you do, the exact pixel resolution of the image no longer affects what you're measuring, only the area it covers.
Also, (1) is not an integer apparently because of weighting of partially masked pixels, in that adding `.unweighted()` to the histogram reducer gives an integer consistent with the `count()`. The partially masked pixels will come from the original image pixels not exactly fitting up to the edges of the pixels of the reduction.
• Interestingly, adding the `.unweighted()` option to the reducer makes the estimate from the histogram even further from the other estimates! It decreases the number of pixels calculated from 4801.474509803917 with the weighting to 4800 without. May 23, 2019 at 19:02