ImageSeriesReader read DICOM series with wrong order

I read DICOM series according to this guide

import SimpleITK as sitk
reader = sitk.ImageSeriesReader()
img2 = reader.Execute()
data2 = sitk.GetArrayFromImage(img2)

However, if I load it to 3D Slicer, the order is correct. I save it to nrrd format in 3D Slicer, and read it using SimpleITK, it’s correct too. Not sure why 3D Slicer read it in the correct order by SimpleITK not. The DICOm reader approach in 3D Slicer is “GDCM with DCMTK fallback”.

Hello @hubutui,

The code you shared looks fine. It assumes that you want to read the first series found in the “patient01” directory, if there are more it will read the first one encountered.

Without the input we cannot reproduce the problem, so can’t really help. Please share the input. If you can’t, due to patient privacy or other reasons, please create an artificial input which causes the same problem and share that.

1 Like

Yes, there is only one series in the dir. Check the sample data here(not available anymore).
BTW, which DICOM tag tells the order of the slice?

That would be Image Position Patient [0020, 0032]. In case that is not enough (e.g. all slices have the same information in this tag), then some other tags can be used as a heuristic.

Hello @hubutui,

Something is wrong with your data, each slice is repeated, just with a different file name. This is exact repetition (subtracting repeated images which only differ by file name yields an image with all zeros). You’ll need to clean this dataset before using it.

I suspect that slicer is either cleaning things up after querying the data or possibly hiding the issue. Code below will highlight the problem (same values for IPP for different slices).

import SimpleITK as sitk

image_file_reader = sitk.ImageFileReader()

file_list = sitk.ImageSeriesReader_GetGDCMSeriesFileNames("patient01")
for file_name in file_list:
    print(f'{file_name}: {image_file_reader.GetMetaData("0020|0032")}') #image position patient
1 Like

If you duplicated every slice then it means the slice spacing alternates between 0 and the real spacing value. Slicer can load this series because it can correctly load images with varying spacing. Still, you should remove the duplicate slices to keep things clean and efficient.

1 Like

Thanks, so I need to keep the file with a unique IPP.
BTW, the sample data is deleted, as this issue is fixed. The data should not be shared anymore.

Yes, I got warning when loading it to Slicer

8: Unnamed Series [Scalar Volume]: Images are not equally spaced (a difference of 0.999803 vs 0 in spacings was detected). If loaded image appears distorted, enable ‘Acquisition geometry regularization’ in Application settings / DICOM / DICOMScalarVolumePlugin. Please use caution.

but I just ignore it.