DICOM (.dcm, .dic)

Background & Context

    • MIME type: application/dicom
    • DICOM medical imaging format.
    • Commonly used in medical imaging equipment and picture archiving and communication systems.
    • DICOM is an acronym for Digital Imaging and Communications in Medicine.
    • Stores multiple raster images together with patient and device information.
    • Binary format.
    • Supports a variety of image encoding and data compression methods.
    • DICOM Version 3.0 was introduced in 1993.

Import & Export

  • Import["file.dcm"] imports a DICOM file, returning an Image object.
  • Import["file.dcm",elem] imports the specified element from a DICOM file.
  • The import format can be specified with Import["file","DICOM"] or Import["file",{"DICOM",elem,}].
  • Export["file.dcm",expr] exports graphics or any other expression as an image to a DICOM file.
  • When exporting Wolfram Language graphics or arbitrary expressions to DICOM, the resulting image has the same raster size as its displayed form.
  • Image objects are by default exported at their raster size.
  • Because DICOM is a raster image format, all fonts are rasterized on export.
  • See the following reference pages for full general information:
  • Import, Exportimport from or export to a file
    CloudImport, CloudExportimport from or export to a cloud object
    ImportString, ExportStringimport from or export to a string
    ImportByteArray, ExportByteArrayimport from or export to a byte array

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Summary"summary of the file
    "Rules"list of rules for all available elements
  • Data representation elements:
  • "Data"array of values
    "Graphics"Graphics object representing an image
    "Image"raster graphics given as an Image object
    "ImageList"a list of images
  • "RawData"array of color map indices
    "RawPixelData"DICOM pixel data without scaling
  • Overlay elements:
  • "Overlays"an overlay image or a list of overlays
  • Import by default uses "Image" for single-frame DICOM files and "ImageList" for multi-frame DICOM files.
  • Advanced Import elements:
  • "BitDepth"bits used to represent each color channel in the file
    "Channels"the number of color channels used in the file
    "ColorMap"color reduction palette, given as a list of color values
    "ColorSpace"color encoding used in the file
    "ImageSize"raster dimensions
    "MetaInformation"metainformation stored in the file
    "RawMetaInformation"raw metainformation stored in the file
    "Summary"summary of the file

Export Elements

  • General Export element:
  • "Rules"a list of imported elements in the form of elemexpr
  • Export["file.dcm",{elem1->expr1,},"Rules"] uses rules to specify the elements to be exported.
  • Available Export elements:
  • "Data"numeric data
    "Image"an Image object
    "Image3D"an Image3D object
    "ImageList"a list of image frames
    "MetaInformation"an association of metadata tags and values
    "Overlays"a list of association
  • The "Overlays" associations can have the following keys:
  • "Description"the overlay description
    "Image"one or a list of overlay images
    "Label"the overlay label
    "Type"the type of the overlay
    "Subtype"the subtype of the overlay
  • Values for "Type" can be either "Graphics" or "RegionOfInterest". "Subtype" can be either "User" or "Automated".

Options

  • Import and Export options:
  • "ImageTopOrientation"Toporientation of the image as stored in the file
    ImageSizeAutomaticoverall image size
    IncludeMetaInformationAllamount of metadata to import and export
  • Possible settings for IncludeMetaInformation include:
  • Allinclude all available metadata
    Noneinclude no metadata
    "Anonymized"include anonymized metadata
    "FullyAnonymized"include fully anonymized metadata
  • Import option:
  • "DataTransformation"Automaticset of transformations applied to the data stored in the file
  • "DataTransformation" can be an association with the following keys:
  • "Modality"Automaticmodality transform to make data manufacturer independent
    "Polarity"Automaticwhether to assume minimum value as black or white
    "Presentation"Automaticwhether to transform to human perceptual response
    "ScalingWindow"Automaticscaling method to use for importing data, also known as values of interest (VOI)
  • By default, the modality transformation specified in the file is used. Use "Modality"None to disable this transform.
  • By default, the polarity transformation specified in the file is used. Possible settings are:
  • "Normal"assume minimum value to be black
    "Reverse"assume minimum value to be white
  • By default, the presentation transformation specified in the file is used. Use "Presentation"None to disable this transform.
  • "ScalingWindow" can take the following settings:
  • Automaticautomatic scaling
    Noneno scaling
    "MinMax"scale to min and max of data in all frames
    "MinMaxPerFrame"scale to min and max of each frame
    {center,w}scale to the range {center-w,center+w}
    <|"Center"center,"Width"w|>scale to the range {center-w,center+w}
    <|"Min"min,"Max"max|>scale to the range {min,max}
  • With "ScalingWindow"->Automatic, values are scaled using scaling values stored in the file. If no scaling specification is stored, values are scaled using the "MinMax" method.
  • Export options:
  • ColorSpaceAutomaticcolor space to be used in the file
    CompressionLevelAutomaticcompression level to use
    ImageSizeAutomaticoverall image size
    "BitDepth"Automaticbit depth per channel used to store image data
    "ImageEncoding"Nonethe image encoding to use
    "ImageTopOrientation"Automaticorientation of the image as stored in the file
  • Supported ColorSpace settings are "Grayscale" and "RGB".
  • Possible values for "ImageEncoding" are "JPEGLossless", "JPEGLosslessNonhierarchical", "JPEGLSLossless", "JPEGLSLossy", "JPEGLossy8Bit", "JPEGLossy12Bit" and "RLE".

Examples

open allclose all

Basic Examples  (3)

Import a DICOM file containing a gray-level image:

Summary of an image:

Export an image to DICOM:

Scope  (2)

Show all Import elements available in the file:

Import the metadata from a DICOM file:

Import Elements  (15)

Available Elements  (3)

List of available elements:

Import all elements as a list of rules:

Import some image options:

The "Options" element does not return all options that are present in the imported image:

Data Representation  (4)

"Data"  (1)

Import the image data:

Create an image from imported data:

"Graphics"  (1)

Import as a Graphics object:

"Image"  (1)

Import as an Image object:

This is the default import element for DICOM:

"RawPixelData"  (1)

Import DICOM pixel data as stored in the file:

The values are returned without any scaling and may not be visible when displayed in an image:

Adjust the values to see more of the data:

Metadata  (8)

"BitDepth"  (1)

Get the number of bits used for representing each color channel:

"Channels"  (1)

Get the number of image channels:

"ColorSpace"  (1)

Get the color encoding used on export:

Use ImageColorSpace to get the color space of an imported image:

"ImageSize"  (1)

Get the dimensions of the image stored in the file:

Using ImageDimensions on an imported image gives the same result:

"MetaInformation"  (1)

Read the metainformation from a DICOM file:

A dataset of metainformation:

"RawMetaInformation"  (2)

Unlike "MetaInformation", "RawMetaInformation" does not validate imported values against the DICOM Standard and does not perform any conversions to Wolfram Language expressions. Read the raw metainformation from a DICOM file:

A dataset of raw metainformation:

The "RawMetaInformation" element may return more tags than "MetaInformation":

"Summary"  (1)

Get the image summary:

Export Elements  (10)

"Data"  (1)

Export NumericArray as raw pixel values to a DICOM file:

"Graphics"  (1)

Any expression can be exported to a DICOM file. If it is not an image, it will be rasterized:

"GraphicsList"  (1)

A list of arbitrary expressions can be exported to a multiframe DICOM file:

"Image"  (1)

Export a single image:

"ImageList"  (1)

Export a list of images to a multi-frame DICOM file:

Images that are of different sizes are conformed to have the same dimensions:

"Image3D"  (1)

Export a 3D image to to a multi-frame DICOM file:

"MetaInformation"  (2)

Export image and meta information to a DICOM file:

Metadata cannot be exported without an image:

"Overlays"  (2)

Define an overlay and the image to be exported:

Export image with the appropriately positioned overlay:

Import the result:

Import just the overlay:

Overlays cannot be exported by themselves:

Import Options  (8)

ImageSize  (1)

By default, images are imported in their full resolution:

Specify the raster size of the imported BMP image:

"ImageTopOrientation"  (1)

By default, images are imported with the top orientation:

Specify the side that is supposed to be on the top:

"DataTransformation"  (6)

Import the image with default data transformations applied:

Check the range of pixel values in the imported image:

Import the image without transformations:

Check the range of pixel values in the imported image:

Check the values of the window width and center stored in the file:

Import the image explicitly specifying the window width and center as stored in the file:

Import image scaling values between 500 and 600 to the full image data range:

Import the image with specific scaling values and reversed polarity:

Compare how disabling modality transformation and changing polarity affects the imported image:

Export Options  (18)

BitDepth  (3)

Export automatically uses the most suitable bit depth:

Force bit depth of the exported image to 8:

Supported bit depths are Automatic, 8 and 16:

ColorSpace  (3)

Export by default uses the most suitable color space:

Force color space to grayscale:

Supported values are Automatic, "Grayscale" and "RGB":

CompressionLevel  (4)

The compression level should be between 0 and 1:

Use CompressionLevel0 for no compression and the best possible image quality:

This leads to a larger file size:

Use CompressionLevel1 for the most compression and the smallest possible file size:

This leads to a smaller file size:

However, it typically introduces artifacts:

Lossless image encodings ignore the compression level:

"ImageEncoding"  (3)

By default, DICOM images are exported with no encoding:

Export the DICOM image with lossy 12-bit JPEG encoding:

Compare file sizes for different encodings:

ImageSize  (1)

By default, the image is exported in the full resolution:

Specify the raster size of exported image:

IncludeMetaInformation  (3)

Import the image with embedded metadata:

By default, embedded metadata is merged with the one specified in "MetaInformation" element:

With IncludeMetaInformationNone, embedded metadata is ignored:

Include embedded meta information with some anonymization:

Notice that the patient name is removed:

While some other metadata, such as procedure start time, persists:

Include embedded meta information with full anonymization:

Note that most metadata is removed or anonymized:

"ImageTopOrientation"  (1)

By default, the upright image is exported using "ImageTopOrientation"->Top:

Specify the orientation: