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

Correction on the last part. sum() does the casting internally so you don't need to do it.
v = uint16([50000, 60000]) % Make a 16 bit array.
theSum = sum(v) % Shows 110000 (double), not 65535
whos theSum
v =
1×2 uint16 row vector
50000 60000
theSum =
110000
Name Size Bytes Class Attributes
theSum 1x1 8 double
Thanks all for your feedback.
I have another question.
1) If i want to know the location(i mean location row and column) for min/max or any value pixel, what is the code to write.
2) If i want to know the total no pixel that have value (range 1000-30000), how to write the code?
3) If i have dicom image(256x256 dimension), how to know the length and width for one pixel. Noted that i know the thickness for one slice is 3.27 mm.
Hope you all can help me. Thank you so much in advanced.
1)
maxValue = max(yourImage(:));
minValue = min(yourImage(:));
2)
mask = yourImage >= 1000 & yourImage <= 30000;
numPixelsInRange = sum(mask(:))
3)
That information should be in the header of the image. Use dicominfo(). If it's missing you'll have to have a known dimension in your image, like the field of view, or the size of some fixed object like a ruler. Then you can spatially calibrate like my attached demo shows.
Thanks Image Analyst.
If i have 30 slice images, i want to sum all the slices that have pixel value range from 1000-30000, how to write the code??
Guillaume
Guillaume on 26 Nov 2017
Edited: Guillaume on 27 Nov 2017
info =
struct with fields:
...
PatientID: ...
PatientBirthDate: ...
PatientSex: ...
PatientAge: ...
PatientSize: ...
PatientWeight: ...
AdditionalPatientHistory: ...
...
I sincerely hope that the above is fake data. Otherwise, whichever country you live in you're most likely in breach of rules regarding patient confidentiality (which could lead to you getting prosecuted).
As for your question, please do make some effort towards trying to solve your problem yourselves rather than bombarding us with thousands of questions.
You've been told how to calculate the number of pixels within your range. Simply mulitply that number by the volume of a pixel to get the volumne you want. It's not hard.
As for finding the volume of a pixel, you can read as well as we can so read the name of each field of your structure and see if it could be the pixel volume. At first glance, it doesn't appear to be present.
Thanks for your help.
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
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)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!