Tags "hidden" inside sequences #1692
-
I am converting an application from IDL to Python. For multiframe images, information pr image can be found within sequences. In IDL I did not have to know anything about the sequence when searching for a specific tag. IDL would return all matches. pydicom return None if the tag is "hidden" within a sequence and I have to specify the sequence first. Is there a way, in pydicom, to get tags that are nested inside sequences without knowing the sequence tag number or name? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I converted this to a discussion issue, as this comes up every now and then. There is no build-in way to do this, but to get the common tags for enhanced image classes, you could write a convenience function, as these tags are always in a nested sequence inside the def get_tag(ds, tag):
if tag in ds:
return ds[tag]
if "SharedFunctionalGroupsSequence" in ds:
item = ds.SharedFunctionalGroupsSequence[0]
for element in item:
if element.VR == "SQ":
if element.value and tag in element.value[0]:
return element.value[0][tag] This will return a
Note that this will show only common tags. Tags that differ between frames can be looked up in a similar way in the |
Beta Was this translation helpful? Give feedback.
-
Thank you for the quick response although it was not the answer I hoped for :) I will not find all the relevant tags in those sequences. At least I will have to add DetectorInformationSequence and RotationInformationSequence for NM multiframe and I guess the list will grow longer as I work dig deeper and work with files from different modalities and vendors. At least, now I know that I will have to create that code myself and find the balance between flexible/slow vs limited/hardcoded/fast. |
Beta Was this translation helpful? Give feedback.
I converted this to a discussion issue, as this comes up every now and then.
There is no build-in way to do this, but to get the common tags for enhanced image classes, you could write a convenience function, as these tags are always in a nested sequence inside the
SharedFunctionalGroupsSequence
:This will return a
DataElement
object: