MATLAB Answers

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

6 views (last 30 days)
Sindhura C
Sindhura C on 19 Jan 2020
Answered: Subhadeep Koley on 22 Jan 2020
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

  0 Comments

Sign in to comment.

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

  0 Comments

Sign in to comment.

Sign in to answer this question.