How do I save a series of dicom-files (slices from a CT scan) to one single dicom file?

15 ビュー (過去 30 日間)
Jesper Brovall
Jesper Brovall 2019 年 2 月 26 日
回答済み: Gautam 2025 年 3 月 7 日
As the title says, how do I save a series of dicom-files (slices from a CT scan) to one single dicom file? It would also work if it's saved as a nrrd-file.
Thanks!

回答 (1 件)

Gautam
Gautam 2025 年 3 月 7 日
Hello, Jesper
You can follow these steps to combine a series of individual DICOM files
  1. Use "dicomread" to load each DICOM slice into MATLAB.
  2. Combine the individual slices into a 3D volume.
  3. Use "dicominfo" from one of the slices to obtain metadata, which will help in writing the stacked file.
  4. Use "dicomwrite" to save the 3D volume as a single DICOM file.
dicomFiles = dir(fullfile(dicomDir, '*.dcm'));
% Read the first DICOM file to get the dimensions and metadata
firstFile = fullfile(dicomDir, dicomFiles(1).name);
firstSlice = dicomread(firstFile);
info = dicominfo(firstFile);
% Preallocate a 3D array to store the volume
numSlices = length(dicomFiles);
volumeData = zeros([size(firstSlice), numSlices], class(firstSlice));
% Read each slice and store it in the volume
for sliceIdx = 1:numSlices
sliceFile = fullfile(dicomDir, dicomFiles(sliceIdx).name);
volumeData(:, :, sliceIdx) = dicomread(sliceFile);
end
% Update metadata for the stacked DICOM file
info.NumberOfFrames = numSlices; % Set the number of frames to the number of slices
% Specify the output filename for the stacked DICOM file
stackedFileName = 'stacked_dicom.dcm';
% Write the 3D volume to a single DICOM file
dicomwrite(volumeData, stackedFileName, info, 'CreateMode', 'Copy');

カテゴリ

Help Center および File ExchangeDICOM Format についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by