How to convert .mat file to .dcm format?

I have imported a RTplan file to Matlab in. dcm format, and I use both functions (dicomread & dicominfo) to work on this file. Now after processing this file in .mat format , I want to convert it to .dcm format , HOW to do it?

 Accepted Answer

file = dicomread(fileName);
imheader = dicominfo(fileName);
dicomwrite(file,'RP.newname.dcm',imheader, 'CreateMode', 'copy');

7 Comments

thank you for answering my question.
I tried and this is the result :
>> file = dicomread('B');
imheader = dicominfo('B');
dicomwrite(file,'RP.newname.dcm',imheader, 'CreateMode', 'copy');
Error using images.internal.dicom.getFileDetails (line 14)
Unable to load file "B".
Error in dicomread>newDicomread (line 197)
fileDetails = images.internal.dicom.getFileDetails(filename, verifyIsDICOM);
Error in dicomread (line 91)
[X, map, alpha, overlays] = newDicomread(msgname, frames, useVRHeuristic);
It depends on how your .mat file is processed.
header = dicominfo('RP_original.dcm'); % RP_original.dcm is the original DICOM file
save('header.mat','header'); % Save the DICOM header into a header.mat file
%
% Then you modify the DICOM header information in your scripts using the
% above mentioned mat file
%
info = dicomread('RP_original.dcm'); % Read the DICOM image,but it is an empty array since it is a RT Plan
%
new_header = load('header.mat'); % Load the modified mat file
% dicomwrite into a new file name
dicomwrite(info, 'RP_newname.dcm', new_header.header,'CreateMode','Copy');
If your dicomread process also save as a .mat file, then the following scripts are also required to replace the last command in the above scripts.
save('info.mat','info');
new_info = load('info.mat');
% dicomwrite into a new file name
dicomwrite(new_info.info, 'RP_newname.dcm', new_header.header,'CreateMode','Copy');
Thank you so much for your help , it works.
Hello,it has warning like this:
warning: The 'SOPClassUID' and 'ObjectType' parameters are ignored when 'CreateMode' is 'copy'.
Someting has lost,how can i fix it?
Thanks!
You should rarely be copying SOPClassUID as that is intended to be a global unique identifier. You would only copy it if the new file is intended to replace the existing file.
I do not know why the routine does not copy ObjectType; the documentation sort of implies that it should copy it.
You can pull it out of dicominfo and write it explicitly using the 'ObjectType' option
My new RTplan cannot import into TPS with CT and RTStructure,did I miss some details?

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2021a

Community Treasure Hunt

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

Start Hunting!