0

I would like to extract from a DICOM all the dicom tags with the same group number. For example, I would like to extract all tags belonging to the group 0010. I tried this, and of course it made an error:

import pydicom
ds=pydicom.dcmread('dicomfile.dcm')

print(ds[0x0008,0x0020]) # print the tag corresponding to group number 0008, and element number 0020

print(ds[0x0010,:]) # ERROR, does not print a list of all tags belonging to group 0008.

Is there a pydicom method to do it?

2
  • 1
    You can use print(ds[0x00100000:0x00110000]). Commented Jan 27, 2022 at 15:37
  • 1
    Or print(ds.group_dataset(0x10))
    – darcymason
    Commented Jan 27, 2022 at 21:09

1 Answer 1

1

As @mrbean-bremen and @darcymason have said, there's two ways to get a range of elements via their tag values. You can return an arbitrary range of elements using slicing:

import pydicom

ds = pydicom.dcmread("path/to/file")
# Must use the full group + element tag
print(ds[0x00100000:0x00110000])

Or if you just need a particular group then you can use Dataset.group_dataset():

import pydicom

ds = pydicom.dcmread("path/to/file")
# Just need the element group number
print(ds.group_dataset(0x0010))

Both methods will return a new Dataset instance containing the elements.

Not the answer you're looking for? Browse other questions tagged or ask your own question.