I want to read a DICOM series with ITK (5.1rc) and compare it with the SimpleITK version:
def read_dcm_series_sitk(files):
file_reader = sitk.ImageFileReader()
file_reader.SetFileName(str(files[0]))
file_reader.ReadImageInformation()
series_ids = [file_reader.GetMetaData('0020|000e')]
with tempfile.TemporaryDirectory() as tmpdir_name:
for f in files:
os.symlink(os.path.abspath(f), os.path.join(tmpdir_name, os.path.basename(f)))
sorted_filenames = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(tmpdir_name, series_ids[0])
sitk_image = sitk.ReadImage(sorted_filenames)
return sitk_image
def read_dcm_series_itk(files):
PixelType = itk.ctype('double') # is int32 available?
ImageType = itk.Image[PixelType, 3]
reader = itk.ImageSeriesReader[ImageType].New()
dicomIO = itk.GDCMImageIO.New()
reader.SetImageIO(dicomIO)
reader.SetFileNames(list(files))
reader.Update()
itk_image = reader.GetOutput()
return itk_image
I now have a list of filenames which constitute a complete CT volume (after applying slope and intercept which ITK internally does becomes int32)
So I read as follows:
itk_image = read_dcm_series_itk(fns)
sitk_image = read_dcm_series_sitk(fns)
Nevertheless, the first axis is flipped:
np.all(itk.array_from_image(itk_image)[::-1] == sitk.GetArrayFromImage(sitk_image))
True
Is this an oversight of mine, and expected behaviour?