Calculation Pixel In range

7 views (last 30 days)
mohd akmal masud
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..

Accepted Answer

Guillaume
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
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
mohd akmal masud
mohd akmal masud on 24 Mar 2019
Sorry all, another question i have but i wrote at this space. please help me
Dear all,
this is my code to view CT image by slice
P = zeros(256, 256, 72);
for K = 1 : 72
petname = sprintf('I4%03d.dcm', K);
P(:,:,K) = dicomread(petname);
end
imshow3D(P)
then, this is my code for view SPECT image by slice,
Noted: all my 42 slice SPECT image stored in one file.
[spect map]=dicomread('128x128');
info = dicominfo('128x128');
gp=info.SliceThickness;
spect=(squeeze(spect));%smooth3
aa=size(spect);aa=aa(3);
imshow3D(spect);
Anybody can help me to fuse both SPECT and CT images for all slice?

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!