Loading Mutiple DICOM images

7 views (last 30 days)
srilekha katkuri
srilekha katkuri on 5 Dec 2015
Commented: Walter Roberson on 5 Dec 2015
hello,
i have 53 DICOM images named 000000.dcm - 000053.dcm. i tried to load images and montage view but i am getting only 53rd image.
mri=zeros(256,256,54);
for i=0:53
if i<=9
a=dicomread(['00000' num2str(i) '.dcm']);
else
a=dicomread(['0000' num2str(i) '.dcm']);
end
a(:,:,i+1)=uint8(a);
end
%%Generate Montage
figure
montage(a(:,:,i+1), 'DisplayRange', [0 255]);
i am getting a warning message as Warning: Suspicious fragmentary file, might not be DICOM. Warning: Not enough data imported. Attempted to read 225731429 bytes at position 8. Only read 132756.

Answers (1)

Walter Roberson
Walter Roberson on 5 Dec 2015
Note: you do not need the 'if':
a = dicomread('000000.dcm');
size0 = size(a);
a(end,end,54) = 0; %for efficiency
for i = 1 : 53
thisfile = sprintf('%06d.dcm', i);
thisdata = dicomread( thisfile );
if ~isequal(size(thisdata), size0)
warning( sprintf('skipped file %s, wrong data size', thisfile ) );
else
a(:,:,i+1) = thisdata;
end
end
This will tell you which files it skipped, and it will leave that slice as all 0.
  2 Comments
srilekha katkuri
srilekha katkuri on 5 Dec 2015
even with this script am getting the same error and same output. its only displaying 000053 image when i try to view files in montage view.
Walter Roberson
Walter Roberson on 5 Dec 2015
a = dicomread('000000.dcm');
size0 = size(a);
a(end,end,:,54) = 0; %for efficiency
for i = 1 : 53
thisfile = sprintf('%06d.dcm', i);
thisdata = dicomread( thisfile );
if ~isequal(size(thisdata), size0)
warning( sprintf('skipped file %s, wrong data size', thisfile ) );
else
a(:,:,:,i+1) = thisdata;
end
end
montage requires the individual images to be in the 4th dimension.
I expect this to still tell you that one of your images is corrupt, but I am expecting that it will tell you which of your images is corrupt, which you would then investigate. Which file is it telling you was skipped?

Sign in to comment.

Categories

Find more on DICOM Format 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!