Apps averaging pixel values above a threshold

I have had a mental block (again).

I am after a way to average the greyscale pixel values above a set threshold. I am not interested in getting an image, and already have the conversion to greyscale (relevant tidbit of code below):

bmp.getPixels(
pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());


for(int x = 0; x < bmp.getWidth(); ++x) {
for(int y = 0; y < bmp.getHeight(); ++y) {
int index = y * bmp.getWidth() + x;
int R = (pixels[index] >> 16) & 0xff;
int G = (pixels[index] >> 8) & 0xff;
int B = pixels[index] & 0xff;


double Grey = (0.299 * R + 0.587 * G + 0.114 * B);

What I need now is how to determine the average Grey value above a set threshold. The part I am having difficulty with is counting how many pixels are left over above the threshold, and adding the values of these pixels.​
 
Top