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

9 views (last 30 days)
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

Answers (1)

Subhadeep Koley
Subhadeep Koley on 22 Jan 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

Categories

Find more on DICOM Format in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!