| Image Processing Toolbox | ![]() |
Reading and Writing DICOM Files
The Image Processing Toolbox includes support for working with image data in Digital Imaging and Communications in Medicine (DICOM) format. The following sections describe how to
To see an example that reads both the image data and metadata from a DICOM file, modifies the image data, and writes the modified data to a new DICOM file, see Example: Creating a New Series. The example shows how to use the dicomuid function to generate a DICOM unique identifier, which you need to create a new series.
Reading Image Data from a DICOM File
To read image data from a DICOM file, use the dicomread function. The dicomread function reads files that comply with the DICOM specification but can also read certain common noncomplying files.
This example reads an image from a sample DICOM file included with the toolbox.
To view the image data, use one of the toolbox image display functions, imshow or imview. (Because the image data is signed 16-bit data, you must use the autoscaling syntax with either display function.)
Reading Metadata from a DICOM File
DICOM files include information, called metadata, that describes characteristics of the image data it contains, such as size, dimensions, and bit depth. In addition, the DICOM specification defines numerous other metadata fields that describe many other characteristics of the data, such as the modality used to create the data, the equipment settings used to capture the image, and information about the study. The dicomread function can process almost all the metadata fields defined by the DICOM specification.
To read metadata from a DICOM file, use the dicominfo function. This function returns the metadata as a structure, where every field in the structure is a specific piece of DICOM metadata.
info = dicominfo('CT-MONO2-16-ankle.dcm'); info = Filename: [1x47 char] FileModDate: '24-Dec-2000 19:54:47' FileSize: 525436 Format: 'DICOM' FormatVersion: 3 Width: 512 Height: 512 BitDepth: 16 ColorType: 'grayscale' SelectedFrames: [] FileStruct: [1x1 struct] StartOfPixelData: 1140 MetaElementGroupLength: 192 FileMetaInformationVersion: [2x1 double] MediaStorageSOPClassUID: '1.2.840.10008.5.1.4.1.1.7' MediaStorageSOPInstanceUID: [1x50 char] TransferSyntaxUID: '1.2.840.10008.1.2' ImplementationClassUID: '1.2.840.113619.6.5' . . .
You can use the metadata structure returned by dicominfo to specify the DICOM file you want to read using dicomread. For example, you can use this code to read metadata from the sample DICOM file and then pass the metadata to dicomread to read the image from the file.
Writing Data to a DICOM File
To write image data to a file in DICOM format, use the dicomwrite function.
This example writes the image I to the DICOM file ankle.dcm.
Writing Metadata to a DICOM File
When you write image data to a DICOM file, dicomwrite includes the minimum set of metadata fields required by the type of DICOM information object (IOD) you are creating. dicomwrite supports three types of DICOM IODs:
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 using dicominfo.
info = dicominfo('CT-MONO2-16-ankle.dcm'); I = dicomread(info); dicomwrite(I,'h:\matlab\tmp\ankle.dcm',info)
In this case, the dicomwrite function writes the information in the metadata structure info to the new DICOM file. When writing metadata to a file, there are certain fields that dicomwrite must update. For example, dicomwrite must update the file modification date in the new file. To illustrate, compare the file modification date in the original metadata with the file modification date in the new file.
Using dicominfo, read the metadata from the newly written file and check the file modification date.
Example: Creating a New Series
When writing a modified image to a DICOM file, you might want to make the modified image the start of a new series. In the DICOM standard, images can be organized into series. When you write an image with metadata to a DICOM file, dicomwrite puts the image in the same series by default. To create a new series, you must assign a new DICOM unique identifier to the SeriesInstanceUID metadata field. This example illustrates this process.
imshow or imview. Because the DICOM image data is signed 16-bit data, you must use the autoscaling syntax.
To remove them, the example sets all pixels with the maximum value to the minimum value.
dicomuid function. You need a new UID to write the modified image as a new series.
SeriesInstanceUID field in the metadata associated with the original DICOM file to the generated value.
info, as an argument. Because you set the SeriesInstanceUID value, the image you write is part of a new series.
| Converting Graphics File Formats | Image Arithmetic | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |