To write image data or metadata to a file in DICOM format, use the
dicomwrite function. This example writes the image
I to the
When writing image data to a DICOM file,
includes the minimum set of metadata fields required by the type of DICOM information object
(IOD) you are creating.
dicomwrite supports the following DICOM IODs with
Secondary capture (default)
dicomwrite can write many other types of DICOM data (e.g., X-ray,
radiotherapy, nuclear medicine) to a file; however,
dicomwrite does not
perform any validation of this data. See
dicomwrite for more information.
You can also specify the metadata you want to write to the file by passing to
dicomwrite an existing DICOM metadata structure that you retrieved
dicominfo. In the following example, the
dicomwrite function writes the relevant information in the metadata
info to the new DICOM file.
info = dicominfo('CT-MONO2-16-ankle.dcm'); I = dicomread(info); dicomwrite(I,'ankle.dcm',info)
Note that the metadata written to the file is not identical to the metadata in the
info structure. When writing metadata to a file, there are certain
dicomwrite must update. To illustrate, look at the instance
ID in the original metadata and compare it with the ID in the new file.
ans = 1.2.840.113622.214.171.1241.1031152382.365.1.736169244
Now, read the metadata from the newly created DICOM file, using
dicominfo, and check the
info2 = dicominfo('ankle.dcm'); info2.SOPInstanceUID
ans = 1.2.841.1134126.96.36.1991.10311244477.365.1.63874544
Note that the instance ID in the newly created file differs from the ID in the original file.