MATLAB: I wanted to read .dcm files for the project from a folder

reading the dicom images from folder

can anyone give me code to read the dicom files from folder and
X = repmat(int16(0), [128 128 1 200]);
dicomFiles = dir('E:\SHIVA BACKUP\THYROID\P1\newcodes\data1\13002\*.dcm');
y=length(dicomFiles)
% Read the series of images.
for p=1:y
%filename = sprintf('IM_%01d.dcm', p);
X(:,:,1,p) = dicomread(dicomFiles);
end
% Display the image stack.
montage(X,[])

Best Answer

projectdir = 'E:\SHIVA BACKUP\THYROID\P1\newcodes\data1\13002';
dicomFiles = dir( fullfile(projectdir, '*.dcm' ));
y = length(dicomFiles)
X = zeros(128, 128, 1, y, 'uint8');
% Read the series of images.
for p=1:y
filename = fullfile( projectdir, dicomFiles(p).name );
X(:,:,1,p) = dicomread(filename);
end
% Display the image stack.
montage(X,[])