extract rescale slope value

22 views (last 30 days)
Hi all,
I want to extract the RescaleSlope value from dicominfo for each slice. But I have 135 slice images. This is my code to extract RescaleSlope. But still failed.
P = zeros(256, 256, 135);
for K = 1 : 135
petname = sprintf('PET_I1001_PT%03d.dcm', K);
P(:,:,K) = dicominfo(petname);
end
info=dicominfo(P(:,:,K));
[r,c,slice] = findND (info.RescaleSlope);
Anyone who can help me solve this problem???

Accepted Answer

Walter Roberson
Walter Roberson on 19 Feb 2018
for K = 135 : -1 : 1
petname = sprintf('PET_I1001_PT%03d.dcm', K);
info(K) = dicominfo(petname);
end
rescale_slopes = [info.RescaleSlope];
If, for some reason you need to find the non-zero entries, then
slice_idx = find(rescale_slopes);
Note: the above code has a limitation that the dicominfo returned by each slice must have exactly the same set of fields. If that assumption is violated then the info(K) assignment will give you an error about assignment between dissimilar structures.
  14 Comments
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 (1)

mohd akmal masud
mohd akmal masud on 8 Nov 2018
Hi Walter
I Have This Code
P = zeros(256, 256, 47);
for K = 20 : 31
petname = sprintf('PETWB001_PT%03d.dcm', K);
P(:,:,K) = dicomread(petname);
end
numOfPixels = numel(P(:));
max(P(:));
sum(P(:));
mask = (P >= 20000 & P <= 32767);
numPixelsInRange = sum(mask(:));
sum(P(P>=20000 & P<=32767));
[r,c,slice] = findND(P >= 20000 & P <= 32767);
val=P(P(:)>=20000 & P(:)<=32767 )
how to multiply the val with RescaleSlope itself?
i have try the code you given like below. its work, but separately. So have to multiply manually. So how to me make automatically?
for K = 47 : -1 : 1
petname = sprintf('PETWB001_PT%03d.dcm', K);
thisinfo = dicominfo(petname);
fn = fieldnames(thisinfo);
for N = 1 : length(fn)
thisfield = fn{N};
info(K).(thisfield) = thisinfo.(thisfield);
end
this_slice = dicomread(petname);
slices{K} = this_slice;
if ~isfield(info(K), 'RescaleSlope') || isempty(info(K).RescaleSlope)
info(K).RescaleSlope = 1;
end
end
rescale_slopes = {info.RescaleSlope};
mask = cellfun(@isempty, rescale_slopes);
rescale_slopes(mask) = {0}; %set missing entries to 0
rescale_slopes = cell2mat(rescale_slopes);
inrange_mask = cellfun(@(M) any(M(:) >= 25000 & M(:) <= 32767), slices);
idx_of_inrange = find(inrange_mask);
rescale_slope_of_inrange = rescale_slopes(20:31)
  5 Comments
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.

Community Treasure Hunt

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

Start Hunting!