I’m using the Statistical API and I’m interested in adding custom calculations. Specifically, I want to calculate the percentage of pixels within a polygon where the NDVI (Normalized Difference Vegetation Index) value is higher than 0.8, or falls within a specific range. Is there a way to achieve this using the Statistical API?

I believe that using the histogram functionality should give you the results you are looking for. Check out this bit of documentation here, and there is a great example here too. In the example, it shows you how to set custom bin widths for your histogram and the output also includes a count of the pixels in that bin.

In addition to the histogram feature, you can also initialise a variable and assign it to 1 if ndvi value meets your condition else 0. Just like how you did for NDVI_R. In this case the mean will be the percentage of pixels within your aoi that meets the condition. Below is an example:

@chung.horng Thank you very much for your responses; I truly appreciate it. I’ve obtained the results I expected. I just have one more question: I’m a bit unclear about the logic behind this ‘mean value’ in relation to calculating a percentage.

Since we assign 1 to pixels which meet the condition and 0 to pixels which don’t, you can imagine that we are counting the number of pixels meeting the condition when calculates the mean. In your case, we plus 1 when there’s a pixel greater than or equal to 0.8 and we plus 0 if the value is less than 0.8. At the end, by dividing the total number of pixels within the AOI, the mean value will be the percentage of pixels that meets the condition.