how to write multiple dicom files into a folder using 'dicomwrite' command

9 visualizzazioni (ultimi 30 giorni)
using for loop, i can read all the 'k' dicom files present in the folder . After performing some operation on each slice, i need to save them into another folder .
Someone please help me
names=dir(fullfile('C:\matlab\*.dcm'));
for k=1:size(names, 1)
I(:,:,k)=dicomread(names(k).name);
P=I(:,:,k);
M(:,:,k) = foperation(P);
%figure(k)
% imshow(Mask(:,:,k))
dicomwrite(Mask(:,:,k),'mask_01.dcm') // what and how should i change this line to save all k files into another folder
end

Risposte (1)

Subhadeep Koley
Subhadeep Koley il 22 Gen 2020
Hi, your code is almost correct. You only need to give different name to the 'k' different DICOM files. The below code might help!
names=dir(fullfile('C:\matlab\*.dcm'));
for k = 1:size(names, 1)
I(:,:,k) = dicomread(names(k).name);
P = I(:,:,k);
M(:,:,k) = foperation(P);
% figure(k);
% imshow(Mask(:,:,k));
dicomwrite(Mask(:,:,k),['putYourFolderPathHere\','mask_01_',num2str(k),'.dcm']);
end

Categorie

Scopri di più su DICOM Format in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by