Calculation Pixel In range
7 views (last 30 days)
Show older comments
mohd akmal masud
on 22 Nov 2017
Commented: mohd akmal masud
on 24 Mar 2019
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..
0 Comments
Accepted Answer
Guillaume
on 22 Nov 2017
Edited: Guillaume
on 22 Nov 2017
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
8 Comments
Image Analyst
on 27 Nov 2017
mohd, I gave you code. The code to sum pixels in the range will work with a 2-D image or a 3-D image (or any D image).
Not sure what "sum all the slices" means. My code sums (counts) the number of pixels in that range. If you want to sum the original gray scale values in the mask, rather than count pixels, then use
pixelValuesInMask = grayImage(mask); % A 1-D list of gray levels.
integratedGrayLevel = sum(pixelValuesInMask);
If your slices are not in a 3-D image but in separate files, then see the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!