how to convert mat file to dcm file
6 views (last 30 days)
Show older comments
Dear All
I have Image as you can download from link here ( https://drive.google.com/file/d/10EUsydCVzIYAaQMXOvzzg4K9L6nw6SLc/view?usp=sharing ).
I tries to convert it into .dcm but failed.
clc
clear all
close all
sz = [128 128 128];
fname = 'nemay90_sca_w1.h00_it4.img';
fid = fopen(fname);
data = fread(fid,'*float'); % assuming uint
fclose(fid);
% this is blindly devectorized
% may still be transposed, but i can't tell due to symmetry
% note that data is binarized on a [0 1000] scale in uint16
% so if viewing in a denormalized manner, it'll just appear black
% normalize or rescale it as needed
data = reshape(data,sz);
data1 = im2uint16(data);
data2 = permute(data1,[3,1,2]);
dicomwrite(data2,'NEWDATA.dcm','CreateMode', 'copy');
ERROR
Error using dicom_copy_IOD>getIOD
Missing required attribute (0008,0016) "SOPClassUID"
Error in dicom_copy_IOD (line 26)
IOD_UID = getIOD(metadata, options, dictionary);
Error in dicomwrite>write_message (line 97)
[attrs, status] = dicom_copy_IOD(X, map, ...
Error in dicomwrite (line 28)
0 Comments
Answers (1)
Walter Roberson
on 11 Oct 2024
When you write a DICOM file, you need to set a number of entries in the data dictionary, including SOPClassUID (but several others as well!)
dicomwrite(data2,'NEWDATA.dcm','CreateMode', 'copy');
CreateMode 'copy' is really only useful if you are passing in meta_struct or info
Creating a DICOM file "from scratch" is a bit of a nuisance, all of the fields that need to be set.
It is usually easier to start with a representative file and copy the headers out of that file, such as
representative_fname = 'nemay_representative.dcm';
representative_info = dicominfo(representative_fname);
dicomwrite(data2,'NEWDATA.dcm', representative_info, 'CreateMode', 'copy');
0 Comments
See Also
Categories
Find more on Convert Image Type 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!