Search code examples
pythondicompydicom

Convert DICOM tag into something more readable


I'm working with pydicom and a DICOMWeb client. The latter I use to fetch metadata from a DICOM repository.

When retrieving DICOM metadata, I only get the DICOM tags as tuples of hexadecimals. I was wondering how to look up the tags and get a readable identifier using pydicom.

For example, how to convert the tag 0x10,0x20 into its string representation/keyword ("PatientID")? (See specs of the DICOM data dictionary)


Solution

  • pydicom offers some utility functions to handle the DICOM data dictionary:

    import pydicom as dicom 
    
    tag = dicom.tag.Tag(0x10,0x20)
    
    # Option 1) Retrieve the keyword:
    keyword = dicom.datadict.keyword_for_tag(tag)
    # Option 2) Retrieve the complete datadict entry:
    entry = dicom.datadict.get_entry(tag)
    representation, multiplicity, name, is_retired, keyword = entry
    
    # keyword: "PatientID"
    # name: "Patient ID"