how to read separetely the odd numbered dicom images and even number dicom images from folder
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
how to read the even number dicom images and oddnumbered dicom images from the same folder using the same code
projectdir = 'E:\SHIVA BACKUP\THYROID\P1\newcodes\data1\13002';
% y = length(projectdir);
y = 72;
Odd = zeros(128, 128, 1, 72, y, 'uint8');
Even = zeros(128, 128, 1, 72, y, 'uint8');
% Read the series of images.
for p=1:1:y
if (mod(p,2)~=0)
thisfile{p} = sprintf('IM_%d.dcm', p);
filename = fullfile( projectdir, thisfile{p});
imdata = dicomread(filename);
imsize = size(imdata);
if ~isequal( imsize, [128 128 1 72] )
fprintf('file is unexpected size %s instead of [128 128 1 72], skipping "%s"\n', mat2str(imsize), filename);
else
count=1;
Odd(:, :, :, :, count) = imdata;
count=count+1;
end
if (mod(p,2)==0)
thisfile{p} = sprintf('IM_%d.dcm', p);
filename = fullfile( projectdir, thisfile{p});
imdata = dicomread(filename);
imsize = size(imdata);
if ~isequal( imsize, [128 128 1 72] )
fprintf('file is unexpected size %s instead of [128 128 1 72], skipping "%s"\n', mat2str(imsize), filename);
else
count=1;
Even(:, :, :, :, count) = imdata;
count=count+1;
end
end
end
end
figure();
% Display the first image stack.
z=montage(Odd(:,:,:,:,p), []);
axis image
title('First file, all layers')
imcontrast(z)
% figure();
% % Display the first layer of all of the stacks
% montage( permute( X(:, :, :, 1, :), [1 2 3 5 4]) )
% title('First layer of all files')
1 comentario
Daniel kiracofe
el 24 de Nov. de 2016
I'm not sure if it's the answer to your question, but these lines are suspicous.
count=1;
Odd(:, :, :, :, count) = imdata;
count=count+1;
Basically, the two lines are overwriting each other. Every time through the loop, count is being reset to 1, which defeats the point of subsequently incrementing it. You will never ever store any data into Odd(:,:,:,:,2), because you keep resetting the value. Suggest that the "count=1" line be moved to the begining, outside the loop. Also, you might need separate counters for even and odd.
Also suggest that you intend your code better. It's really hard to read as is.
Respuestas (0)
Ver también
Categorías
Más información sobre DICOM Format en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!