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, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import 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" Top orientation of the image as stored in the file ImageSize Automatic overall image size IncludeMetaInformation All amount of metadata to import and export - Possible settings for IncludeMetaInformation include:
-
All include all available metadata None include no metadata "Anonymized" include anonymized metadata "FullyAnonymized" include fully anonymized metadata - Import option:
-
"DataTransformation" Automatic set of transformations applied to the data stored in the file - "DataTransformation" can be an association with the following keys:
-
"Modality" Automatic modality transform to make data manufacturer independent "Polarity" Automatic whether to assume minimum value as black or white "Presentation" Automatic whether to transform to human perceptual response "ScalingWindow" Automatic scaling 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:
-
Automatic automatic scaling None no 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:
-
ColorSpace Automatic color space to be used in the file CompressionLevel Automatic compression level to use ImageSize Automatic overall image size "BitDepth" Automatic bit depth per channel used to store image data "ImageEncoding" None the image encoding to use "ImageTopOrientation" Automatic orientation 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 allBasic Examples (3)Summary of the most common use cases
Scope (2)Survey of the scope of standard use cases
Show all Import elements available in the file:

https://wolfram.com/xid/0hkhc4k5q8-g7tsey

Import the metadata from a DICOM file:

https://wolfram.com/xid/0hkhc4k5q8-1i8t43

Import Elements (15)
Available Elements (3)

https://wolfram.com/xid/0hkhc4k5q8-1g2ndh

Import all elements as a list of rules:

https://wolfram.com/xid/0hkhc4k5q8-myzd73


https://wolfram.com/xid/0hkhc4k5q8-bvl5fv

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

https://wolfram.com/xid/0hkhc4k5q8-kx49o5

Data Representation (4)
"Data" (1)
"Graphics" (1)
Import as a Graphics object:

https://wolfram.com/xid/0hkhc4k5q8-oxk5kn


https://wolfram.com/xid/0hkhc4k5q8-oxk2tw

"Image" (1)
Import as an Image object:

https://wolfram.com/xid/0hkhc4k5q8-vtuh6c


https://wolfram.com/xid/0hkhc4k5q8-1f07e2

This is the default import element for DICOM:

https://wolfram.com/xid/0hkhc4k5q8-s0naad

"RawPixelData" (1)
Import DICOM pixel data as stored in the file:

https://wolfram.com/xid/0hkhc4k5q8-gzb4jz

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

https://wolfram.com/xid/0hkhc4k5q8-qsfjwi

Adjust the values to see more of the data:

https://wolfram.com/xid/0hkhc4k5q8-kcwg4r

Metadata (8)
"BitDepth" (1)
"Channels" (1)
"ColorSpace" (1)
Get the color encoding used on export:

https://wolfram.com/xid/0hkhc4k5q8-wb968h

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

https://wolfram.com/xid/0hkhc4k5q8-ca8qqr

"ImageSize" (1)
Get the dimensions of the image stored in the file:

https://wolfram.com/xid/0hkhc4k5q8-ma62cc

Using ImageDimensions on an imported image gives the same result:

https://wolfram.com/xid/0hkhc4k5q8-hjusgl

"MetaInformation" (1)
"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:

https://wolfram.com/xid/0hkhc4k5q8-48sw08

A dataset of raw metainformation:

https://wolfram.com/xid/0hkhc4k5q8-yxtpw1

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

https://wolfram.com/xid/0hkhc4k5q8-9bwuh5

Export Elements (10)
"Data" (1)
Export NumericArray as raw pixel values to a DICOM file:

https://wolfram.com/xid/0hkhc4k5q8-jdgj4m


https://wolfram.com/xid/0hkhc4k5q8-3qv4u8

"Graphics" (1)
"GraphicsList" (1)
"Image" (1)
"ImageList" (1)
Export a list of images to a multi-frame DICOM file:

https://wolfram.com/xid/0hkhc4k5q8-rt0ue1

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

https://wolfram.com/xid/0hkhc4k5q8-04xqlb


https://wolfram.com/xid/0hkhc4k5q8-prabuq

"Image3D" (1)
"MetaInformation" (2)
Export image and meta information to a DICOM file:

https://wolfram.com/xid/0hkhc4k5q8-1hq048


https://wolfram.com/xid/0hkhc4k5q8-omfnch

https://wolfram.com/xid/0hkhc4k5q8-4yey1f


https://wolfram.com/xid/0hkhc4k5q8-jr0a32

Metadata cannot be exported without an image:

https://wolfram.com/xid/0hkhc4k5q8-u1ftgt


"Overlays" (2)
Define an overlay and the image to be exported:

https://wolfram.com/xid/0hkhc4k5q8-kkzs2h

https://wolfram.com/xid/0hkhc4k5q8-roj48w

Export image with the appropriately positioned overlay:

https://wolfram.com/xid/0hkhc4k5q8-b9wixw

https://wolfram.com/xid/0hkhc4k5q8-3xifq2


https://wolfram.com/xid/0hkhc4k5q8-x70zmf

Overlays cannot be exported by themselves:

https://wolfram.com/xid/0hkhc4k5q8-382jw4


Import Options (8)
ImageSize (1)
By default, images are imported in their full resolution:

https://wolfram.com/xid/0hkhc4k5q8-ty3hak


https://wolfram.com/xid/0hkhc4k5q8-i0v3f2

Specify the raster size of the imported BMP image:

https://wolfram.com/xid/0hkhc4k5q8-df7mw1


https://wolfram.com/xid/0hkhc4k5q8-d5h5xu

"ImageTopOrientation" (1)
"DataTransformation" (6)
Import the image with default data transformations applied:

https://wolfram.com/xid/0hkhc4k5q8-s0fp9j

Check the range of pixel values in the imported image:

https://wolfram.com/xid/0hkhc4k5q8-18j37q

Import the image without transformations:

https://wolfram.com/xid/0hkhc4k5q8-6ao5y0

Check the range of pixel values in the imported image:

https://wolfram.com/xid/0hkhc4k5q8-nzjo8q

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

https://wolfram.com/xid/0hkhc4k5q8-7qwknw

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

https://wolfram.com/xid/0hkhc4k5q8-ewkgyd

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

https://wolfram.com/xid/0hkhc4k5q8-l1qs5h

Import the image with specific scaling values and reversed polarity:

https://wolfram.com/xid/0hkhc4k5q8-8671j6

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

https://wolfram.com/xid/0hkhc4k5q8-ukrfvl

https://wolfram.com/xid/0hkhc4k5q8-w9cb7z

Export Options (18)
BitDepth (3)
Export automatically uses the most suitable bit depth:

https://wolfram.com/xid/0hkhc4k5q8-cxmspd


https://wolfram.com/xid/0hkhc4k5q8-fm4tou

Force bit depth of the exported image to 8:

https://wolfram.com/xid/0hkhc4k5q8-uwg6e6


https://wolfram.com/xid/0hkhc4k5q8-d56cwr

Supported bit depths are Automatic, 8 and 16:

https://wolfram.com/xid/0hkhc4k5q8-hui2yt


ColorSpace (3)
Export by default uses the most suitable color space:

https://wolfram.com/xid/0hkhc4k5q8-0ymmkm


https://wolfram.com/xid/0hkhc4k5q8-1dxu2v

Force color space to grayscale:

https://wolfram.com/xid/0hkhc4k5q8-v1oz4r


https://wolfram.com/xid/0hkhc4k5q8-fsyz2x

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

https://wolfram.com/xid/0hkhc4k5q8-ynrski


CompressionLevel (4)
The compression level should be between 0 and 1:

https://wolfram.com/xid/0hkhc4k5q8-oq5sk5

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

https://wolfram.com/xid/0hkhc4k5q8-iocasn
This leads to a larger file size:

https://wolfram.com/xid/0hkhc4k5q8-19ewjz

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

https://wolfram.com/xid/0hkhc4k5q8-qqjv9y
This leads to a smaller file size:

https://wolfram.com/xid/0hkhc4k5q8-618z36

However, it typically introduces artifacts:

https://wolfram.com/xid/0hkhc4k5q8-4hy3jv

Lossless image encodings ignore the compression level:

https://wolfram.com/xid/0hkhc4k5q8-l83vub

https://wolfram.com/xid/0hkhc4k5q8-o6w1cr


https://wolfram.com/xid/0hkhc4k5q8-imas7t

"ImageEncoding" (3)
By default, DICOM images are exported with no encoding:

https://wolfram.com/xid/0hkhc4k5q8-sb3z2l

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

https://wolfram.com/xid/0hkhc4k5q8-38jzw1

Compare file sizes for different encodings:

https://wolfram.com/xid/0hkhc4k5q8-b6a676

https://wolfram.com/xid/0hkhc4k5q8-bx3idc

ImageSize (1)
By default, the image is exported in the full resolution:

https://wolfram.com/xid/0hkhc4k5q8-lszysm

https://wolfram.com/xid/0hkhc4k5q8-bhjnpf


https://wolfram.com/xid/0hkhc4k5q8-t9ntr8


https://wolfram.com/xid/0hkhc4k5q8-7p8hv4

Specify the raster size of exported image:

https://wolfram.com/xid/0hkhc4k5q8-3ie1wu


https://wolfram.com/xid/0hkhc4k5q8-ss5jdi

IncludeMetaInformation (3)
Import the image with embedded metadata:

https://wolfram.com/xid/0hkhc4k5q8-j5vdry

https://wolfram.com/xid/0hkhc4k5q8-qd874h

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

https://wolfram.com/xid/0hkhc4k5q8-ovtm2p

https://wolfram.com/xid/0hkhc4k5q8-v6o49

With IncludeMetaInformationNone, embedded metadata is ignored:

https://wolfram.com/xid/0hkhc4k5q8-ml0i2k

https://wolfram.com/xid/0hkhc4k5q8-vqkitw

Include embedded meta information with some anonymization:

https://wolfram.com/xid/0hkhc4k5q8-wnphjc

https://wolfram.com/xid/0hkhc4k5q8-khugct

Notice that the patient name is removed:

https://wolfram.com/xid/0hkhc4k5q8-2l39us

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

https://wolfram.com/xid/0hkhc4k5q8-dst0e

Include embedded meta information with full anonymization:

https://wolfram.com/xid/0hkhc4k5q8-54g7j3

https://wolfram.com/xid/0hkhc4k5q8-gzvod0

Note that most metadata is removed or anonymized:

https://wolfram.com/xid/0hkhc4k5q8-femce


https://wolfram.com/xid/0hkhc4k5q8-dic399

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

https://wolfram.com/xid/0hkhc4k5q8-kje3az

https://wolfram.com/xid/0hkhc4k5q8-9ogv7d


https://wolfram.com/xid/0hkhc4k5q8-oj40fq


https://wolfram.com/xid/0hkhc4k5q8-i70bei


https://wolfram.com/xid/0hkhc4k5q8-olrxst
