Skip to main content

DICOM files parser meant to facilitate data access.

Project description

Documentation Status PyPI version PyPI status Coverage


dicom_parser is a utility python package meant to facilitate access to DICOM header information by extending the functionality of pydicom.

Essentially, dicom_parser uses DICOM's data-element value-representation (VR), as well as prior knowledge on vendor-specific private tags or encoding schemes, in order to transform them to more "pythonic" data structures when possible.

For more information, please see the documentation.


To install the latest version of dicom_parser, simply run:

    pip install dicom_parser


The most basic usage case is reading a single DICOM image (.dcm file) as an Image instance.

    from dicom_parser import Image

    # Create a DICOM Image object
    image = Image('/path/to/dicom/file.dcm')

Coversion to Python's native types

dicom_parser provides dict-like access to the parsed values of the header's data-elements. The raw values as read by pydicom remain accessible through the raw attribute.


Decimal String (DS) to float using the Header class's get method:

    raw_value = image.header.raw['ImagingFrequency'].value
    >> "123.25993"
    >> str

    parsed_value = image.header.get('ImagingFrequency')
    >> 123.25993
    >> float

Age String (AS) to float:

    raw_value = image.header.raw['PatientAge'].value
    >> "027Y"
    >> str

    parsed_value = image.header.get('PatientAge')
    >> 27.0
    >> float

Date String (DA) to using the Header class's indexing operator/subscript notation:

    raw_value = image.header.raw['PatientBirthDate'].value
    >> "19901214"
    >> str

    parsed_value = image.header['PatientBirthDate']
    >>, 12, 14)

Et cetera.

The dict-like functionality also includes safe getting:

    >> None
    image.header.get('MissingKey', 'DefaultValue')
    >> 'DefaultValue'

As well as raising a KeyError for missing keys with the indexing operator:

    >> ...
    >> KeyError: "The keyword: 'MissingKey' does not exist in the header!"

Read DICOM series directory as a Series

Another useful class this package offers is the Series class:

    from dicom_parser import Series

    series = Series('/path/to/dicom/series/')

    # Read stacked pixel arrays as a 3D volume
    >>> numpy.ndarray
    >> (224, 224, 208)

    # Access the underlying Image instances
    >> 7    # instance numbers are 1-indexed

Reading Siemens 4D data encoded as mosaics is also supported:

    fmri_series = Series('/path/to/dicom/fmri/')
    >> (96, 96, 64, 200)

For more information, please see the documentation.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for dicom-parser, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size dicom_parser-0.1.2-py3-none-any.whl (55.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size dicom_parser-0.1.2.tar.gz (29.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page