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 full validation.
Secondary capture (default)
dicomwrite can write many other types of DICOM data (such as X-ray,
radiotherapy, or nuclear medicine) to a file. However,
not perform any validation of this data.
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.1136220.127.116.111.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.113418.104.22.1681.10311244477.365.1.63874544
Note that the instance ID in the newly created file differs from the ID in the original file.
Each field of DICOM metadata (known as an attribute or data element), includes a tag that identifies the attribute, information about the length of the attribute, and the attribute data. The attribute optionally includes a two-letter value representation (VR) that identifies the format of the attribute data. For example, the format can be a single-precision binary floating point number, a character vector that represents a decimal integer, or a character vector in the format of a date-time.
To include the VR in the attribute when using
'VR' name-value pair argument as
you do not specify the VR, then
dicomwrite infers the value
representation from the data dictionary.
The figure shows an attribute with and without the VR.