How do I save a series of dicom-files (slices from a CT scan) to one single dicom file?
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Respuestas (1)
Gautam
el 7 de Mzo. de 2025
Hello, Jesper
You can follow these steps to combine a series of individual DICOM files
- Use "dicomread" to load each DICOM slice into MATLAB.
- Combine the individual slices into a 3D volume.
- Use "dicominfo" from one of the slices to obtain metadata, which will help in writing the stacked file.
- 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');
0 comentarios
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!