SimpleITK fails to load DICOM metadata

#1

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:

# This example worked on old Slicer
i = sitk.ReadImage('image.dcm')
i.GetMetaDataKeys()
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())
reader = sitk.ImageFileReader()
reader.SetFileName('image.dcm')
reader.ReadImageInformation();
reader.GetMetaDataKeys();
(Csaba Pinter) #2

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:

(Andras Lasso) #3

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).

#4

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.

(Andras Lasso) #5

DICOM exporter is implemented in Python and uses createdicomseries module. You can use it as an example.

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 works.