Good morning everyone,
I am trying to use the itk GDCM reader in Python. This is what I wrote so far to read from a folder, as a ITK beginner:
reader = itk.ImageSeriesReader.New()
dicomIO = itk.GDCMImageIO.New()
name = dicomIO.GetPatientName('')
found, spacing2 = dicomIO.GetValueFromTag("0028|0030", "")
Now the thing is, I am sure the DICOM folder I am trying to read is valid. I am also sure that the patient name and the tag (“0028,0030”) I am trying to read (a spacing value) are present in the metadata. However, this code just gives me no result.
Am I supposed to write that another way around ?
In general it feels like most of the functions of this module have not really been written for Python. I could be missing some part of the documentation though…
Thanks for your help. Bests.
You need to call Update() on your reader to actually do the reading.
ITK Python is “just” a wrapping from the C++, explaining that it doesn’t look very pythonic.
You can look at SimpleITK which is more user-friendly and have python binaries. I know efforts have been made to enable a more pythonic logic and syntax in it. @blowekamp should be able to be more precise that me.
I agree with Tim that a missing
Update() is likely the cause of the problem. ITK has a pipeline architecture, that must be explicitly updated to be executed. This is a fundamental concept of ITK and is describe in the ITK Software Guide.
Regarding SimpleITK, it has been designed with an easier and more pythonic interface. We have a related example for printing meta-data (DICOM tags).
There is also a more complex example which reads a series copies select tags and writes a new series.
Thank you @tim-evain and @blowekamp, that was exactly the problem !