MATLAB: Obtain the mean all pixels above & below a threshold.

for loopimageImage Processing Toolboxmeanthreshold

I want to find all pixels above a threshold in a gray scale image, I therefore use:
[ii,jj]=find(IM>(thresh));
Is there a way to find the mean value of all those pizels above the threshold (i.e. at locations ii,jj) without using for loop?

Best Answer

Try it this way:
mask = grayImage > someThresholdValue;
theMean = mean(grayImage(mask))
mask is a 2D binary (logical) image.
grayImage(mask) is a vector (list of values.)
Related Question