Reading Header Information

DICOM images have a lot of infomation stored in header tags. django_dicom includes a reader package that provides both a HeaderInformation class that facilitates interaction with the header data, and a DicomParser class that handles parsing of DICOM data elements into native python types.

We can easily query header fields using either their name or their tag through an Image instance’s header property:

from django_dicom.models import Image

image = Image.objects.last()

# Querying using the DICOM attribute name:
image.header.get_value("InstanceCreationTime")
# Out: datetime.time(12, 44, 46, 263000)

# Querying the Patient's Age attribute using its DICOM tag:
image.header.get_value(("0010", "1010"))
# Out: 27.0
# (the parser automatically returns the age as a float representing whole years)

# If we want the raw header value:
image.header.get_value(("0010", "1010"), parsed=False)
# Out: '027Y'