1

I have few codes that count number of pixels in different classes in GEE, and then calc the precentage of them using the total number of pixels that were count. The code seems to work, but when I check the results, I find out that it never count all the pixels. for example, here is the results of raster that has only 3 possible class values- high, mean and low.

If you sum all the count, you don't get to the total count numner (338+598+771 =1707, not 1789), and then ,also when I calc precentage I never get to 100%.

enter image description here

I believe it's result of the way that GEE works with polygon that on the border (e.g takes only "whole" pixels), but is there any way to change it and to make it count all of the pixels?

My end goal: when I calculate precentage, to get to 100%.

Edit: link to sample code which has the same problem: https://code.earthengine.google.com/761d16596d243e9bc0d053fa84fa2c66

4
  • It would be very useful to have the code which generates your output. Otherwise troubleshooting is a lot of guesswork.
    – JonasV
    Apr 13 '20 at 8:21
  • @JonasV I have edited my question and now it has the code
    – Reut
    Apr 13 '20 at 14:40
  • @Reut You have to make your assets public for us to access them. I don't know if this applies to your case, but you didn't mention the possibility that some of your pixels are NoData. I believe the "polygon-border" cases will be the same method for the individual class counts and the overall count, so I doubt that's the source of the discrepancy (but I'm not sure).
    – Jon
    Apr 13 '20 at 14:45
  • @JonasV I think now it suppose to be shared, let me know if not. there are not suppose to be pixels with no data
    – Reut
    Apr 13 '20 at 14:47
2
+50

I believe it's result of the way that GEE works with polygon that on the border (e.g takes only "whole" pixels), but is there any way to change it and to make it count all of the pixels?

You are right about the borders. According to the docs:

By default, reducers applied to imagery weight the inputs according to the mask value.

You can make a count reducer unweighted by calling ee.Reducer.count().unweighted(). There seems to be a caveat when you combine multiple reducers though, so I'd make all of the combined reducers unweighted.

Here's your code with unweighted reducers, and counts/percentages adding up: https://code.earthengine.google.com/b92700bd7f454ceeaff53306d3d54ac5

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.