# Reading Dicom sequence data with SimpleITK

**URL:** https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877
**Category:** Engineering
**Tags:** dicom, simpleitk
**Created:** [March 28, 2020, 4:20pm UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877 "2020-03-28T16:20:57Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![jonasteuwen](https://discourse.itk.org/user_avatar/discourse.itk.org/jonasteuwen/32/1335_2.png) [@jonasteuwen](https://discourse.itk.org/u/jonasteuwen)
#### Post date: [March 28, 2020, 4:20pm UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/1 "2020-03-28T16:20:57Z")

</div>

When reading mammography images there are several Dicom tags relevant to be able to display the image correctly as described [in the dicom standard](http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.11.2.html). These are stored in the `VOILUTFunction` and `VOILUTSequence`. The first is a low-level tag, and can be easily read, however, the second does not.

For instance, `dcmdump` gives this for my file:

```
(base) ➜ pngs dcmdump mammogram.dcm | grep -i lut
(0028,1055) LO [linear LUT] # 10, 1 WindowCenterWidthExplanation
(0028,3010) SQ (Sequence with explicit length #=4) # 32974, 1 VOILUTSequence
    (0028,3002) US 4096\0\12 # 6, 3 LUTDescriptor
    (0028,3003) LO [Flavor3_35_280] # 14, 1 LUTExplanation
    (0028,3006) US 0\6\6\6\6\6\6\6\6\7\7\7\7\7\7\7\7\7\7\7\7\7\7\7\7\7\7\7\7\7\7\7\7\7... # 8192,4096 LUTData
    (0028,3002) US 4096\0\12 # 6, 3 LUTDescriptor
    (0028,3003) LO [Flavor3_37_250] # 14, 1 LUTExplanation
    (0028,3006) US 0\10\10\10\10\10\10\10\10\10\10\10\10\10\10\10\11\11\11\11\11\11\11... # 8192,4096 LUTData
    (0028,3002) US 4096\0\12 # 6, 3 LUTDescriptor
    (0028,3003) LO [Flavor3_37_230] # 14, 1 LUTExplanation
    (0028,3006) US 0\11\11\11\11\11\11\11\11\11\12\12\12\12\12\12\12\12\12\12\12\12\12... # 8192,4096 LUTData
    (0028,3002) US 4096\0\12 # 6, 3 LUTDescriptor
    (0028,3003) LO [Flavor3_LUT1] # 12, 1 LUTExplanation
    (0028,3006) US 0\17\17\17\17\17\18\18\18\18\18\18\18\18\18\18\18\18\18\18\18\18\19... # 8192,4096 LUTData

```

While with SimpleITK I get:

```
sitk_image.GetMetaData('0028|3010')

RuntimeError: Exception thrown in SimpleITK Image_GetMetaData: /Users/runner/runners/2.160.0/work/1/sitk-build/ITK/Modules/Core/Common/src/itkMetaDataDictionary.cxx:88:
itk::ERROR: Key '0028|3010' does not exist 

```

Is there a way of doing this currently with SimpleITK or would it be better to use `pydicom` for this? It would be a little bit unfortunate, as this would mean I need to read the header twice (and have another dependency).

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.itk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.itk.org/u/flaviu2)
#### Post date: [March 28, 2020, 6:05pm UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/2 "2020-03-28T18:05:51Z")

</div>

Seem that itkMetaDataDictionary class doesn’t know that tag, so an overcome will be to read that tag before SimpleITK with other lib/object, either to delete that tag, or, modify it, and consider later as you needs.

If you app allow to read the data with VTK, I can help you.

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [March 28, 2020, 7:11pm UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/3 "2020-03-28T19:11:37Z")

</div>

Hello @jonasteuwen,

Generally speaking SimpleITK will read all the tags and they should be accessible.  
How are you reading the images, [ImageFileReader](https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1ImageFileReader.html#adb2e5921b4d0ea0e077bac998b6fd3de) or [ImageSeriesReader](https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1ImageSeriesReader.html)? Are all other tags loaded ([GetMetaDataKeys](https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1Image.html#afeccb3e540a7c462af21707408cdc8b6))?

Possibly if you could share the code used for reading and the image we could better help you (preferably both, but just the code would help in understanding what went wrong).

---

<div class="post-metadata">

### Author: ![jonasteuwen](https://discourse.itk.org/user_avatar/discourse.itk.org/jonasteuwen/32/1335_2.png) [@jonasteuwen](https://discourse.itk.org/u/jonasteuwen)
#### Post date: [March 28, 2020, 8:02pm UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/4 "2020-03-28T20:02:30Z")

</div>

Hi @zivy

I am reading the image as follows (mammograms are single dicom files): `img = sitk.ReadImage(fn)`. Other DICOM tags are properly read, and are in `GetMetaDataKeys`, however `'0028|3010'` is not. For instance, the modality tag `img.GetMetaData('0008|0060')` properly returns `MG`.

For instance this piece of code (with `ImageFileReader`) also does not output the sequence tags:

```
reader = sitk.ImageFileReader()

reader.SetFileName(image_fn)
reader.LoadPrivateTagsOn();

reader.ReadImageInformation();

for k in reader.GetMetaDataKeys():
    v = reader.GetMetaData(k)
    print(k, v)

```

Best,  
Jonas

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [March 28, 2020, 9:34pm UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/5 "2020-03-28T21:34:53Z")

</div>

Hi @jonasteuwen,

Code looks good, so it may be an issue with SimpleITK/ITK, possibly related to [this question](https://discourse.itk.org/t/reading-and-writing-a-dicom-slice-in-itk-with-gdcm-removes-tags/861/3). Underneath the SimpleITK hood we are using GDCM, which does have a Python binding ([Examples here](https://github.com/malaterre/GDCM/tree/master/Examples/Python)).

If you can share the data we may be able to debug this or identify if we have missing functionality.

---

<div class="post-metadata">

### Author: ![jonasteuwen](https://discourse.itk.org/user_avatar/discourse.itk.org/jonasteuwen/32/1335_2.png) [@jonasteuwen](https://discourse.itk.org/u/jonasteuwen)
#### Post date: [March 29, 2020, 11:13am UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/6 "2020-03-29T11:13:54Z")

</div>

Dear @zivy, in that case I think it is a missing feature. I will see if I can find data which can be shared with such sequence information. Likely the same issue will arise with a CT scan with an associated RTSTRUCT.

Best,  
Jonas.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [March 29, 2020, 1:10pm UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/7 "2020-03-29T13:10:11Z")

</div>

Hello,

What version of SimpleITK are you using? It may be worth trying SimpleITK 2.0 rc 1, as GDCM version has been updated which might address the issue.

> [@SimpleITK 2.0 Release Candidate 1](https://discourse.itk.org/t/simpleitk-2-0-release-candidate-1/2851):
>
> Announcement Announcing the SimpleITK 2.0 Release Candidate 1! NOTE: SimpleITK neither supports Python 2.7 nor provides 32-bit binaries as of version 2.0. Installing SimpleITK Complete instructions on getting started with SimpleITK including downloading binaries or building SimpleITK can be found on the SimpleITK [Read the Docs web page](https://simpleitk.readthedocs.io/en/master/installation.html). Python Binary Downloads Including Python 3.8 support! Python binary wheels are available for download. It is important to have the latest version of pip for…

---

<div class="post-metadata">

### Author: ![jonasteuwen](https://discourse.itk.org/user_avatar/discourse.itk.org/jonasteuwen/32/1335_2.png) [@jonasteuwen](https://discourse.itk.org/u/jonasteuwen)
#### Post date: [April 13, 2020, 1:37pm UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/8 "2020-04-13T13:37:06Z")

</div>

Hello Bradley,

I can confirm the problem still persists, I am only able to access the top-level keys tags, and no childs (which definitely exist if I check the output of `dcmdump`). I am not very familiar with the ITK source code, but if you could point me to the relevant part of the Metadata reading of DICOM images, I might be able to find the reason.

Best,  
Jonas

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [April 13, 2020, 3:07pm UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/9 "2020-04-13T15:07:19Z")

</div>

Hello,

SimpleITK used GDCM for reading the DICOM files and metadata. You can find the library on GitHub here:

> **[malaterre/GDCM](https://github.com/malaterre/GDCM)**
>
> Grassroots DICOM read-only mirror. Only for Pull Request. Please report bug at http://sf.net/p/gdcm - malaterre/GDCM

The ITK class which interfaces with GDCM is here:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/GDCM/src/itkGDCMImageIO.cxx>

@mathieu.malaterre is the maintainer of GDCM. I believe there should be some GDCM tools to inspect you file to verify if GDCM is doing the right thing, of if there is a problem with ITKGDCMImageIO.

---

<div class="post-metadata">

### Author: ![mihail.isakov](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mihail.isakov](https://discourse.itk.org/u/mihail.isakov)
#### Post date: [April 13, 2020, 4:01pm UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/10 "2020-04-13T16:01:36Z")

</div>

ITKGDCMImageIO doesn’t read sequences for metadata dictionary, s. [here](https://github.com/InsightSoftwareConsortium/ITK/blob/60924a512a38c65b2050ad905fd94b11541d0e10/Modules/IO/GDCM/src/itkGDCMImageIO.cxx#L686) and [here](https://github.com/InsightSoftwareConsortium/ITK/blob/60924a512a38c65b2050ad905fd94b11541d0e10/Modules/IO/GDCM/src/itkGDCMImageIO.cxx#L693). It was never supported and already mentioned several times, e.g. the [topic](https://discourse.itk.org/t/unable-to-get-dicom-sq-tags-from-simpleitk-series-reader-metadata-keys/2321).

---

<div class="post-metadata">

### Author: ![jonasteuwen](https://discourse.itk.org/user_avatar/discourse.itk.org/jonasteuwen/32/1335_2.png) [@jonasteuwen](https://discourse.itk.org/u/jonasteuwen)
#### Post date: [April 13, 2020, 8:27pm UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/11 "2020-04-13T20:27:58Z")

</div>

Hi,

Thanks for figuring out where this is located. Is this a intended feature for ITK (I suppose that the sequences load slower) or would it be possible to allow to load this, e.g. with `LoadDicomSequences()` just as with `LoadPrivateTags()`? It seems more important than the private tags - imagine you want to match an RTSTRUCT with its CT scan. The ReferenceFrameUID is part of a sequence.

The DCMTK backend [seems to support sequences](https://github.com/InsightSoftwareConsortium/ITK/blob/60924a512a38c65b2050ad905fd94b11541d0e10/Modules/IO/DCMTK/src/itkDCMTKFileReader.cxx#L69).

---

<div class="post-metadata">

### Author: ![mihail.isakov](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mihail.isakov](https://discourse.itk.org/u/mihail.isakov)
#### Post date: [April 14, 2020, 4:43am UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/12 "2020-04-14T04:43:49Z")

</div>

Yes, i also think that sequences are absolutely important and that without sequences it doesn’t make sense to rely on metadata dictionary for DICOM attributes at all. Currently it is better to take pydicom (or low level GDCM / DCMTK for C++), if there is a requirement to access attributes.

P.S. Also, not sure it will be a good idea to add support for whole data set in meta data dictionary, but it is another, longer story.

---

<div class="post-metadata">

### Author: ![jonasteuwen](https://discourse.itk.org/user_avatar/discourse.itk.org/jonasteuwen/32/1335_2.png) [@jonasteuwen](https://discourse.itk.org/u/jonasteuwen)
#### Post date: [April 14, 2020, 1:49pm UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/13 "2020-04-14T13:49:50Z")

</div>

It would at least be an idea to allow the reading of the whole dictionary (just as it allows reading of the private tags), or expose a method to lookup the tag, or disable it so we can implement more efficient means using DCMTK.

---

<div class="post-metadata">

### Author: ![jdhenckel](https://discourse.itk.org/user_avatar/discourse.itk.org/jdhenckel/32/2681_2.png) [@jdhenckel](https://discourse.itk.org/u/jdhenckel)
#### Post date: [May 13, 2022, 4:00pm UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/14 "2022-05-13T16:00:36Z")

</div>

I am using python with nibabel and pydicom and sitk cobbled together is a very awkward way. I would **love** to stop using the former two and use sitk exclusively… except for this ONE bug. Sequences are not supported. Can someone please fix this bug? It was reported over two years ago!

---

<div class="post-metadata">

### Author: ![dutking](https://discourse.itk.org/user_avatar/discourse.itk.org/dutking/32/3739_2.png) [@dutking](https://discourse.itk.org/u/dutking)
#### Post date: [October 31, 2023, 7:41am UTC](https://discourse.itk.org/t/reading-dicom-sequence-data-with-simpleitk/2877/15 "2023-10-31T07:41:50Z")

</div>

Issue still exists. I have just faced it trying to read Segmentation Storage dcm.
