How to save in dicom format
11 views (last 30 days)
Show older comments
Dear All,
I have one file as attached. Then, I open it using my script as below.
Anyone can help me how to save the dataHU (as in my script) in dicom format?
clc
clear all
close all
sz = [128 128 128];
fname = 'nemaho166ab.ict';
fid = fopen(fname);
data = fread(fid,'*float'); % assuming uint
fclose(fid);
data = reshape(data,sz);
imshow3D(data)
muwater = 0.182868;
mudata = data;
dataHU = ((mudata - muwater)./ (muwater-0))*1000;
figure, imshow3D(dataHU);
5 Comments
Walter Roberson
on 28 Feb 2025
MetaData = struct('SpecificCharacterSet', 'ISO_IR 100', ...
'ImageType', 4, ...
'SOPClassUID', '1.2.840.10008.5.1.4.1.1.2', ...
%stuff
'SeriesTime', 133355.245000, ...
'Manufacturer', 'SIEMENS', ...
%stuff
);
dicomwrite(YourData, YourFileName, MetaData)
Answers (1)
Madheswaran
on 8 Aug 2025
Hello Mohd Akmal Masud,
To summarize the discussions in the comments: MATLAB requires this metadata to be in a "struct" variable to create a valid DICOM file from your "dataHU" matrix.
Here is the syntax from the documentation for your context: "dicomwrite(___,meta_struct)" specifies optional metadata or file options in the structure "meta_struct". The names of fields in "meta_struct" must be the names of DICOM file attributes or options. The value of a field is the value you want to assign to the attribute or option.
The code below shows the minimal steps to create the metadata structure and save a single slice of your data.
% your existing code
% clc
% clear all
% ... (your code goes here)
% dataHU = ...
% create the metadata structure
% The field names (e.g., 'StudyDescription') must match DICOM attribute names.
% This example uses a few attributes from the list you provided.
meta = struct();
meta.StudyDescription = 'Tumor Imaging';
meta.Modality = 'CT';
meta.Manufacturer = 'SIEMENS';
meta.PatientID = '12345'; % A DICOM file requires some patient info
% selecting the first slice to store
slice_data = dataHU(:, :, 1);
dicomwrite(slice_data, 'output_slice.dcm', meta);
For more information, refer to the following MathWorks documentation: https://mathworks.com/help/images/ref/dicomwrite.html
I hope this helps!
0 Comments
See Also
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!