I am trying to read diffusion MRI scans using SimpleITK in Python. I am using the ImageFileReader with the GDCMImageIO interface. In the DICOM header the tag (0028, 0004) Photometric Interpretation is set as MONOCHROME1. So when I execute the reader I have inverted images. Is there a way to make the GDCMImageIO set the photometric interpretation at MONOCHROME2?
What version of SimpleITK are you using? This may have been fixed in ITK recently. Please try SimpleITK 2.0rc1 to see if the issue still exists.
Thanks for the quick response!
I am currently using SimpleITK 2.0rc1
photometric_interpretation = image_file_reader.GetMetaData('0028|0004').strip() if photometric_interpretation == 'MONOCHROME1': image = -image + max_value
Thanks for the solution zivy!
Is there perhaps a way to modify the behaviour of the GDCMImageIO from Python?
I noticed in your link to the C++ code that there is a method called: “SetPhotometricInterpretation”. Is there a way to invoke this from the python code?
Unfortunately that is a gdcm method which is not exposed by ITK, so no.
Using your ad-hoc work around I unfortunately get: ERROR: Pixel type: 16-bit unsigned integer is not supported in 3D byN3itk6simple21UnaryMinusImageFilterE
However, I have managed to modify the code very slightly and it works just fine:
photometric_interpretation = reader.GetMetaData('0028|0004').strip() if photometric_interpretation == 'MONOCHROME1': image = image*-1 + max(image)
An alternative for me is just to edit the PhotometricInterpretation DICOM tag to be MONOCHROME2 before reading it with SimpleITK.
Thanks for your help!
I would recommend the following ( untested code ):
mmFilter = sitk.MinimumMaximumImageFilter() mmFilter.Execute(image) image = sitk::InvertIntensity(image, maximum=mmFilter.GetMaximum())
This uses a fast filter as opposed to image iterators that
max uses. And uses the InvertIntensity filter so that you are not doing funky negative multiplication with an unsigned integer.
Thanks, works great!