MATLAB: Calculation Pixel In range

pixel

Hi everyone,
I have min pixel value 0 and max pixel value 32767. How to me write the code if i want summation the pixel value from 1000 – 30000???
Anyone please help me..

Best Answer

Assuming that your image is of class double, then
sum(yourimage(yourimage >= 1000 & yourimage <= 30000)))
EDIT: As Image Analyst pointed out sum converts its input to double, so you can ignore the following:
If your image is of class int16, then convert it to double before doing the sum. (Otherwise, any sum above 32767 will be returned as 32767)
yourimage = double(yourimage); %if class(yourimage) is not double