How to save in dicom format

12 次查看(过去 30 天)
mohd akmal masud
mohd akmal masud 2025-2-28
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 个评论
mohd akmal masud
mohd akmal masud 2025-2-28
Sorry Sir, can you please write for me the example.?
Walter Roberson
Walter Roberson 2025-2-28
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)

请先登录,再进行评论。

回答(1 个)

Madheswaran
Madheswaran 2025-8-8
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!

类别

Help CenterFile Exchange 中查找有关 DICOM Format 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by