Search code examples
pythonpython-3.xpython-2.7dicompydicom

How to fetch a dicom element from a .dcm file using pydicom if an element is in square brackets


I am trying to extract a dicom file using pydicom library.

    filename="C:\\Users\\1016086\\PycharmProjects\\untitled\\dicomeSample.dcm'
    dataset = pydicom.dcmread(filename)

So, I have to get the value of below element (0011, 1004) [Acquisition Type] CS: 'SE'

But I couldn't get the value of 'Acquisition Type' since it is in square brackets.

I have tried dataset.get(Acquisition Type) and dataset.get_item(Acquisition Type) But it is not showing error in python IDE since it has space in between the key 'Acquisition Type'


Solution

  • Items with square brackets are private tags, not dicom keywords, and pydicom does not accept those as they are not necessarily unique. They are displayed only as a convenience.

    You have to access those by the tag number, e.g. ds[(0x0011, 0x1004)].value

    Edited: added '0x' in front of hex numbers in tag