# SimpleITK fails to load DICOM metadata

**URL:** <https://discourse.slicer.org/t/simpleitk-fails-to-load-dicom-metadata/6822>\
**Category:** Support\
**Created:** [May 16, 2019, 5:54pm UTC](https://discourse.slicer.org/t/simpleitk-fails-to-load-dicom-metadata/6822 "2019-05-16T17:54:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ulla](https://avatars.discourse-cdn.com/v4/letter/u/c67d28/32.png) [@Ulla](https://discourse.slicer.org/u/Ulla)\
**Post date:** [May 16, 2019, 5:54pm UTC](https://discourse.slicer.org/t/simpleitk-fails-to-load-dicom-metadata/6822/1 "2019-05-16T17:54:26Z")

</div>

I’m using SimpleITK inside my Python scripted module to read metadata from DICOMs. It worked on older Slicer versions (4.6 and 4.8) but I cannot make it work on Slicer 4.10.1. The problem happens on all DICOM files I have tried.

Works:  
SimpleITK version is 1.1.0dev (ITK 4.12) on Slicer-4.8 and 1.1.0 (ITK 4.13) on Slicer 4-10.1

Doesn’t work:  
SimpleITK version 1.1.0 (ITK 4.13). (This SimpleITK works on system Python but not inside Slicer)

Example codes:

```auto
# This example worked on old Slicer
i = sitk.ReadImage('image.dcm')
i.GetMetaDataKeys()

```

```auto
imageReader= sitk.ImageSeriesReader()
path='/directory/'
series_ids = imageReader.GetGDCMSeriesIDs(path)
imageReader.MetaDataDictionaryArrayUpdateOn()
series_file_names = imageReader.GetGDCMSeriesFileNames(path, series_ids[0])
imageReader.SetFileNames(series_file_names)
imageReader.MetaDataDictionaryArrayUpdateOn()
reader.LoadPrivateTagsOn();
image = imageReader.Execute()
print(image.GetMetaDataKeys())

```

```auto
reader = sitk.ImageFileReader()
reader.SetFileName('image.dcm')
reader.ReadImageInformation();
reader.GetMetaDataKeys();

```

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [May 16, 2019, 7:44pm UTC](https://discourse.slicer.org/t/simpleitk-fails-to-load-dicom-metadata/6822/2 "2019-05-16T19:44:07Z")

</div>

DICOM importing and loading is quite difficult in general, and that’s why Slicer provides advanced tools for this. Please see convenience functions here, with special attention to the `importDicom` and `loadPatient` functions:

> <https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMLib/DICOMUtils.py>

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 17, 2019, 3:14am UTC](https://discourse.slicer.org/t/simpleitk-fails-to-load-dicom-metadata/6822/3 "2019-05-17T03:14:15Z")

</div>

SimpleITK’s capabilities for accessing DICOM tags are very limited anyway, so I would not bother trying to make that work. You can access some common tags in Slicer database and you can get proper, full access to all fields using pydicom (bundled with Slicer).

---

<div class="post-metadata">

**Author:** ![Ulla](https://avatars.discourse-cdn.com/v4/letter/u/c67d28/32.png) [@Ulla](https://discourse.slicer.org/u/Ulla)\
**Post date:** [May 17, 2019, 4:19am UTC](https://discourse.slicer.org/t/simpleitk-fails-to-load-dicom-metadata/6822/4 "2019-05-17T04:19:25Z")

</div>

Thanks for the answers. I’m not trying to load or import DICOMs on Slicer. My goal is to make a dicom series writer which suits for my work better than the “create a DICOM series” -module. In my module, I am selecting a file from the DicomDatabase and then I want to copy parts of the header to a new DICOM file. I have also tried to access the “create a DICOM series” -module from python script but couldn’t found out how to use it from `slicer.modules.createdicomseries`.

With Slicer-4.8 GetMetaDataKeys returns a list of tags but with Slicer-4.10.1 GetMetaDataKeys returns an empty list without errors. My module works on Slicer-4.8 as expected and I’m interested to know why it doesn’t work with newer versions since the header reading works with the same SimpleITK version outside Slicer.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 17, 2019, 4:24am UTC](https://discourse.slicer.org/t/simpleitk-fails-to-load-dicom-metadata/6822/5 "2019-05-17T04:24:04Z")

</div>

> [@Ulla](#):
>
> I have also tried to access the “create a DICOM series” -module from python script but couldn’t found out how to use it from `slicer.modules.createdicomseries` .

[DICOM exporter](https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMLib/DICOMExportScalarVolume.py) is implemented in Python and uses createdicomseries module. You can use it as an example.

> [@Ulla](#):
>
> I want to copy parts of the header to a new DICOM file

For this purpose, pydicom is the best tool in Python (in C++ I would recommend DCMTK or GDCM). For example, this is how the [DICOM Patcher module](https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMPatcher/DICOMPatcher.py) works.

---

<div class="post-metadata">

**Author:** ![Ulla](https://avatars.discourse-cdn.com/v4/letter/u/c67d28/32.png) [@Ulla](https://discourse.slicer.org/u/Ulla)\
**Post date:** [May 21, 2019, 1:27pm UTC](https://discourse.slicer.org/t/simpleitk-fails-to-load-dicom-metadata/6822/6 "2019-05-21T13:27:42Z")

</div>

Thank you! I think I got it working with Create a DICOM series -module and pydicom.
