Skip to content

ImageSeriesReader create an incorrect direction matrix #2292

Done

Description

@MMRohe

Describe the bug

I have the a series comprising 413 dicom slices the "ImagePositionPatient" tag for the slices are :
slice 1 : -216.500 \ -216.500 \ 70.000
slice 2: -216.500 \ -216.500 \ 68.750
.....
slice 413 : -216.500 \ -216.500 \ -445.000

The "ImageOrientation" is the same for all tags :
(0020,0037) Image Orientation Patient 1.000000\0.000000\0.000000\0.000000\1.000000\0.000000

I read these slices with the Image Series Reader:

reader = sitk.ImageSeriesReader()
reader.SetFileNames(dcm_list)
image = reader.Execute()

Reading the slice from the last to the first (bottom to top), the metadata of the final 3d image is inconsistant with the values of the dicom tags :
image.GetOrigin() -> (-216.5, -216.5, -445.0) seems OK
image.GetDirection() -> (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0) not OK last vector should be 1 instead of -1

if I put the slices from the first to the last I get correct results :
image.GetOrigin() ->(-216.5, -216.5, 70.0) seems OK
image.GetDirection() -> (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0) now it is OK since we are reading from top to bottom

so depending on the order of the slice given, one give a coherent result in term of metadata and the other does not.

My understanding was that the code computed the 3d direction matrix with both the "image orientation" for the first two axes, and the vector defined by the vector separing the "image position patient" of the two first slice given. In that case it should be 0 / 0 / 1 when reading the image from bottom to top and 0 / 0 / -1 from top to bottom but last vector is always 0 / 0 / -1

To Reproduce
Hard to reproduce without sharing the dcm files itself, on request it can be done

Thanks !

Here are the full information of the final 3d image for reference :


Image (0x40bcd700)
  RTTI typeinfo:   itk::Image<int, 3u>
  Reference Count: 1
  Modified Time: 16338
  Debug: Off
  Object Name:
  Observers:
    none
  Source: (none)
  Source output name: (none)
  Release Data: Off
  Data Released: False
  Global Release Data: Off
  PipelineMTime: 1807
  UpdateMTime: 16334
  RealTimeStamp: 0 seconds
  LargestPossibleRegion:
    Dimension: 3
    Index: [0, 0, 0]
    Size: [512, 512, 413]
  BufferedRegion:
    Dimension: 3
    Index: [0, 0, 0]
    Size: [512, 512, 413]
  RequestedRegion:
    Dimension: 3
    Index: [0, 0, 0]
    Size: [512, 512, 413]
  Spacing: [0.845703, 0.845703, 1.25]
  Origin: [-216.5, -216.5, -445]
  Direction:
1 0 0
0 1 0
0 0 -1

  IndexToPointMatrix:
0.845703 0 0
0 0.845703 0
0 0 -1.25

  PointToIndexMatrix:
1.18245 0 0
0 1.18245 0
0 0 -0.8

  Inverse Direction:
1 0 0
0 1 0
0 0 -1

  PixelContainer:
    ImportImageContainer (0x40f65de0)
      RTTI typeinfo:   itk::ImportImageContainer<unsigned long, int>
      Reference Count: 1
      Modified Time: 1875
      Debug: Off
      Object Name:
      Observers:
        none
      Pointer: 0x7fdb14418010
      Container manages memory: true
      Size: 108265472
      Capacity: 108265472

Activity

  1. blowekamp commented on May 14, 2025

    @blowekamp
    Member

    Does the following code reproduce your issue?

    """
    Reproduce DICOM direction bug as described in user report:
    - Create 3-slice image with ImagePositionPatient and ImageOrientationPatient tags
    - Write slices as DICOM files
    - Read back in both orders, print origin and direction
    """
    
    import shutil
    import SimpleITK as sitk
    from pathlib import Path
    
    # Output directory for DICOM slices
    dicom_dir = Path("dicom_bug_repro")
    if dicom_dir.exists():
        shutil.rmtree(dicom_dir)
    dicom_dir.mkdir()
    
    # Create a 3D image (3 slices)
    size = [2, 2, 3]
    image = sitk.Image(size, sitk.sitkUInt16)
    image += 100  # Just to have nonzero pixel values
    # DICOM meta-data values from the report
    positions = [
        "-216.500\\-216.500\\70.000",   # slice 1 (top)
        "-216.500\\-216.500\\-187.500", # slice 2 (middle)
        "-216.500\\-216.500\\-445.000"  # slice 3 (bottom)
    ]
    orientation = "1.000000\\0.000000\\0.000000\\0.000000\\1.000000\\0.000000"
    
    # Write each slice as a DICOM file with appropriate tags
    writer = sitk.ImageFileWriter()
    writer.KeepOriginalImageUIDOn()
    for i in range(3):
        slice_img = image[:, :, i]
        # Set required DICOM tags
        slice_img.SetMetaData("0020|0032", positions[i])  # ImagePositionPatient
        slice_img.SetMetaData("0020|0037", orientation)   # ImageOrientationPatient
        slice_img.SetMetaData("0008|0060", "CT")         # Modality
        slice_img.SetMetaData("0020|0013", str(i+1))      # InstanceNumber
        slice_img.SetMetaData("0010|0010", "Test^Patient")
        slice_img.SetMetaData("0020|000e", f"1.2.3.4.5.6.7.8.{i+1}")
        filename = dicom_dir / f"slice_{i+1}.dcm"
        writer.SetFileName(str(filename))
        writer.Execute(slice_img)
    
    # List of DICOM files, top-to-bottom and bottom-to-top
    files_top_to_bottom = [dicom_dir / f"slice_{i+1}.dcm" for i in range(3)]
    files_top_to_bottom = [str(f) for f in files_top_to_bottom]
    files_bottom_to_top = list(reversed(files_top_to_bottom))
    
    # Read in top-to-bottom order
    reader = sitk.ImageSeriesReader()
    reader.SetFileNames(files_top_to_bottom)
    image1 = reader.Execute()
    print("Top-to-bottom order:")
    print(f"  Origin: {image1.GetOrigin()}")
    print(f"  Direction: {image1.GetDirection()}")
    print(f"  Spacing: {image1.GetSpacing()}")
    
    # Read in bottom-to-top order
    reader.SetFileNames(files_bottom_to_top)
    image2 = reader.Execute()
    print("Bottom-to-top order:")
    print(f"  Origin: {image2.GetOrigin()}")
    print(f"  Direction: {image2.GetDirection()}")
    print(f"  Spacing: {image2.GetSpacing()}")
    
    # Clean up
    del image1, image2
    shutil.rmtree(dicom_dir)
    
  2. MMRohe commented on May 14, 2025

    @MMRohe
    Author

    Hello @blowekamp

    thanks for your help ! here is the output of your sample code here :

    python test_dicom_bug.py
    Top-to-bottom order:
      Origin: (-216.5, -216.5, 70.0)
      Direction: (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)
      Spacing: (1.0, 1.0, 257.5)
    Bottom-to-top order:
      Origin: (-216.5, -216.5, -445.0)
      Direction: (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)
      Spacing: (1.0, 1.0, 257.5)
    

    So it seems to reproduce the bug on my side, both image have same direction while logically they should be reverse on the last axis

  3. MMRohe commented on May 14, 2025

    @MMRohe
    Author

    I have investigated the issue a little bit more, using your code @blowekamp and testing with "plain itk" and I found that there is a discrepency between itk and sitk results. itk giving the right and expected whereas sitk has this error for the direction matrix, so it seems to be a sitk-problem,

    It seems to be because sitk "force" orthogonal direction even though the slice are not, and the itk option "ForceOrthogonalDirectionOff" fixes this issue. it seems quite weird because it makes the final image not having the right meta data in term of physical direction as it is not implied by the dcm tag but force to be orthogonal. Do you know if there is a way to prevent this behavior in a similar way of "ForceOrthogonalDirectionOff" of itk ?

    Here is the modified code snapshot, using both itk and sitk to read the same image :

    import shutil
    import SimpleITK as sitk
    import itk
    
    from pathlib import Path
    import os
    
    # Output directory for DICOM slices
    dicom_dir = Path("dicom_bug_repro")
    if dicom_dir.exists():
        shutil.rmtree(dicom_dir)
    os.mkdir(dicom_dir)
    
    # Create a 3D image (3 slices)
    size = [2, 2, 3]
    image = sitk.Image(size, sitk.sitkUInt16)
    image += 100  # Just to have nonzero pixel values
    # DICOM meta-data values from the report
    positions = [
        "-216.500\\-216.500\\70.000",  # slice 1 (top)
        "-216.500\\-216.500\\-187.500",  # slice 2 (middle)
        "-216.500\\-216.500\\-445.000",  # slice 3 (bottom)
    ]
    orientation = "1.000000\\0.000000\\0.000000\\0.000000\\1.000000\\0.000000"
    
    # Write each slice as a DICOM file with appropriate tags
    writer = sitk.ImageFileWriter()
    writer.KeepOriginalImageUIDOn()
    for i in range(3):
        slice_img = image[:, :, i]
        # Set required DICOM tags
        slice_img.SetMetaData("0020|0032", positions[i])  # ImagePositionPatient
        slice_img.SetMetaData("0020|0037", orientation)  # ImageOrientationPatient
        slice_img.SetMetaData("0008|0060", "CT")  # Modality
        slice_img.SetMetaData("0020|0013", str(i + 1))  # InstanceNumber
        slice_img.SetMetaData("0010|0010", "Test^Patient")
        slice_img.SetMetaData("0020|000e", f"1.2.3.4.5.6.7.8.{i+1}")
        filename = dicom_dir / f"slice_{i+1}.dcm"
        writer.SetFileName(str(filename))
        writer.Execute(slice_img)
    
    # List of DICOM files, top-to-bottom and bottom-to-top
    files_top_to_bottom = [dicom_dir / f"slice_{i+1}.dcm" for i in range(3)]
    files_top_to_bottom = [str(f) for f in files_top_to_bottom]
    files_bottom_to_top = list(reversed(files_top_to_bottom))
    
    # Read in top-to-bottom order
    reader = sitk.ImageSeriesReader()
    reader.SetFileNames(files_top_to_bottom)
    image1 = reader.Execute()
    print("Top-to-bottom order:")
    print("   With sitk:")
    print(f"     Origin: {image1.GetOrigin()}")
    print(f"     Direction: {image1.GetDirection()}")
    print(f"     Spacing: {image1.GetSpacing()}")
    
    PixelType = itk.ctype("signed short")
    ImageType = itk.Image[PixelType, 3]
    reader_itk = itk.ImageSeriesReader[ImageType].New()
    dicomIO = itk.GDCMImageIO.New()
    reader_itk.SetImageIO(dicomIO)
    reader_itk.SetFileNames(files_top_to_bottom)
    reader_itk.ForceOrthogonalDirectionOff()
    reader_itk.Update()
    
    image1 = reader_itk.GetOutput()
    
    # Read the image series
    print("   With itk:")
    print(f"     Origin: {image1.GetOrigin()}")
    print(f"     Direction: {image1.GetDirection()}")
    print(f"     Spacing: {image1.GetSpacing()}")
    
    # Read in bottom-to-top order
    reader.SetFileNames(files_bottom_to_top)
    image2 = reader.Execute()
    print("Bottom-to-top order:")
    print("   With sitk:")
    print(f"     Origin: {image2.GetOrigin()}")
    print(f"     Direction: {image2.GetDirection()}")
    print(f"     Spacing: {image2.GetSpacing()}")
    
    reader_itk.SetFileNames(files_bottom_to_top)
    reader_itk.ForceOrthogonalDirectionOff()
    reader_itk.Update()
    image2 = reader_itk.GetOutput()
    print("   With itk:")
    print(f"     Origin: {image2.GetOrigin()}")
    print(f"     Direction: {image2.GetDirection()}")
    print(f"     Spacing: {image2.GetSpacing()}")
    
    # Clean up
    del image1, image2
    shutil.rmtree(dicom_dir)
    
    

    and here is the output I get, with the itk / sitk difference :

    
    Top-to-bottom order:
       With sitk:
         Origin: (-216.5, -216.5, 70.0)
         Direction: (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)
         Spacing: (1.0, 1.0, 257.5)
       With itk:
         Origin: itkPointD3 ([-216.5, -216.5, 70])
         Direction: itkMatrixD33 ([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, -1.0]])
         Spacing: itkVectorD3 ([1, 1, 257.5])
    Bottom-to-top order:
       With sitk:
         Origin: (-216.5, -216.5, -445.0)
         Direction: (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)
         Spacing: (1.0, 1.0, 257.5)
       With itk:
         Origin: itkPointD3 ([-216.5, -216.5, -445])
         Direction: itkMatrixD33 ([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]])
         Spacing: itkVectorD3 ([1, 1, 257.5])
    
  4. blowekamp commented on May 14, 2025

    @blowekamp
    Member

    It looks like the behavior of this "ForceOrthogonalDirection" is buggy in ITK. And it looks like SimpleITK is not exposing this operations. I'll add it to SimpleITK as a work around, but it needs further investigation into the ITK code.

    However, there is a default (required?) order returned by sitk::ImageSeriesReader::GetGDCMSeriesFileNames that is expected to work. I am not sure of all the DICOM details, and perhaps some DICOM experts can chime in here, with the DICOM standards.

    @dzenanz InsightSoftwareConsortium/ITK@23436a0

  5. MMRohe commented on May 15, 2025

    @MMRohe
    Author

    Hey @blowekamp I have managed to reproduce and investigate a little bit more the results, it seems that the sITK / ITK (and actually it seems to be a ITK issue) uses a some points the tag "SpacingBetweenSlice" to put an intermediate slice spacing value even though the Z spacing is correctly computed at the end using the interslice distance. This behaviour makes it bug somehow with the "ForceOrthogonalDirection" method, because I suspect that at this point it uses the intermediate (and unreliable / wrong) value "SpacingBetweenSlice" instead of the actual distance between two consecutive slice.

    To reproduce the issue one can read two consecutive set of dcm slices just changing the value "SpacingBetweenSlice". It does not impact the Z spacing which is correctly computed, but it impact the direction matrix because of this buggy "ForceOrthogonalDirection" here you can find the output of the sample code below when putting a dummy value of -20 in "SpacingBetweenSlice" :

    Without negative spacing between slice:
         Origin: (-216.5, -216.5, 70.0)
         Direction: (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)
         Spacing: (1.0, 1.0, 257.5)
    With negative spacing between slice:
         Origin: (-216.5, -216.5, 70.0)
         Direction: (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0)
         Spacing: (1.0, 1.0, 257.5)
    

    One can see that even though ITK/sITK correctly ignore this value in computing the spacing (but instead use the interslice distance), the fact that this value was added in the dcm tag cause the direction matrix to be wrongly computed by, i guess, "ForceOrthogonalDirection"

    
    import shutil
    import SimpleITK as sitk
    import itk
    
    from pathlib import Path
    import os
    import pydicom
    
    # Output directory for DICOM slices
    dicom_dir = Path("/home/mmrohe/Data/dicom_bug_repro")
    if dicom_dir.exists():
        shutil.rmtree(dicom_dir)
    os.mkdir(dicom_dir)
    
    # Create a 3D image (3 slices)
    size = [2, 2, 3]
    image = sitk.Image(size, sitk.sitkUInt16)
    image += 100  # Just to have nonzero pixel values
    # DICOM meta-data values from the report
    positions = [
        "-216.500\\-216.500\\70.000",  # slice 1 (top)
        "-216.500\\-216.500\\-187.500",  # slice 2 (middle)
        "-216.500\\-216.500\\-445.000",  # slice 3 (bottom)
    ]
    orientation = "1.000000\\0.000000\\0.000000\\0.000000\\1.000000\\0.000000"
    
    # Write each slice as a DICOM file with appropriate tags
    writer = sitk.ImageFileWriter()
    writer.KeepOriginalImageUIDOn()
    for i in range(3):
        slice_img = image[:, :, i]
        # Set required DICOM tags
        slice_img.SetMetaData("0020|0032", positions[i])  # ImagePositionPatient
        slice_img.SetMetaData("0020|0037", orientation)  # ImageOrientationPatient
        slice_img.SetMetaData("0008|0060", "CT")  # Modality
        slice_img.SetMetaData("0020|0013", str(i + 1))  # InstanceNumber
        slice_img.SetMetaData("0010|0010", "Test^Patient")
        slice_img.SetMetaData("0020|000e", f"1.2.3.4.5.6.7.8.{i+1}")
        filename = dicom_dir / f"slice_{i+1}.dcm"
        writer.SetFileName(str(filename))
        writer.Execute(slice_img)
    
    # List of DICOM files, top-to-bottom and bottom-to-top
    files_standard = [str(dicom_dir / f"slice_{i+1}.dcm") for i in range(3)]
    
    # Read in top-to-bottom order
    reader = sitk.ImageSeriesReader()
    reader.SetFileNames(files_standard)
    
    image1 = reader.Execute()
    print("Without negative spacing between slice:")
    print(f"     Origin: {image1.GetOrigin()}")
    print(f"     Direction: {image1.GetDirection()}")
    print(f"     Spacing: {image1.GetSpacing()}")
    
    files_standard_neg_spacing = []
    
    for i in range(3):
        file = files_standard[i]
        # Load the DICOM file
        ds = pydicom.dcmread(file)
        # Set spacing between slices to a negative value
        ds.SpacingBetweenSlices = -20.0
        # Save modified file
        output_path = dicom_dir / f"slice_withneg_{i+1}.dcm"
        ds.save_as(output_path)
        files_standard_neg_spacing.append(output_path)
    
    reader.SetFileNames(files_standard_neg_spacing)
    reader.MetaDataDictionaryArrayUpdateOn()
    image2 = reader.Execute()
    print("With negative spacing between slice:")
    print(f"     Origin: {image2.GetOrigin()}")
    print(f"     Direction: {image2.GetDirection()}")
    print(f"     Spacing: {image2.GetSpacing()}")
    
    # Clean up
    del image1, image2
    shutil.rmtree(dicom_dir)
    
  6. blowekamp commented on May 15, 2025

    @blowekamp
    Member

    These inline code examples are getting unwieldily. It may be better to use GH gist to share the code blocks.

  7. dzenanz commented on May 15, 2025

    @dzenanz
    Collaborator

    I think that InsightSoftwareConsortium/ITK@23436a0 is backwards compatible, with ForceOrthogonalDirection being the only behavior before that commit. Does the problem persist if you revert that commit?

  8. MMRohe commented on May 15, 2025

    @MMRohe
    Author

    I did not try to revert the commit, but I tested with simpleitk ==2.3.1 (instead of simpleitk == 2.4.1) which fixes the problem. So it seems that the issue appers somewhere inbetween version 2.3.1 and 2.4.1. I did not yet have time to investigate the changes of ITK corresponding to moving from SimpleITK 2.3.1 -> 2.4.1 and whether the commit you are referencing is part of it

  9. blowekamp commented on May 15, 2025

    @blowekamp
    Member

    If you run print(sitk.Version()) information about the SimpleITK and ITK version is printed. SimpleITK 2.3.1 has a version of ITK along the 5.3.0 release branch and 2.4.1 should have ITK 5.4.3.

    I am currently testing the "ReverseOrder" flag and I'm getting some unexpected behavior with the image bulk data I'm currently looking into. This issue might be able to be when the image file name order is revered, the meta-data in ITK is the same answer as the original order.

  10. MMRohe commented on May 16, 2025

    @MMRohe
    Author

    Ok thanks ! so it seems to be indeed a bug on the ForceOrthogonalDirection method added in ITK 5.4.3, not sure if I should open a new issue on the ITK github ?

  11. dzenanz commented on May 16, 2025

    @dzenanz
    Collaborator

    ForceOrthogonalDirection was added in 2018, and first appeared in a tagged release with v5.0b01. I am afraid this issue is unrelated to that feature.

  12. blowekamp commented on May 16, 2025

    @blowekamp
    Member

    The work around with the ForceOrthoganaDirection option is now available in the SimpleITK latest release:
    https://github.com/SimpleITK/SimpleITK/releases/tag/latest

  13. zhurong2020 commented on Oct 3, 2026

    @zhurong2020

    Hi @blowekamp,

    Thanks for fixing this in InsightSoftwareConsortium/ITK#5357. We tested several SimpleITK builds with a synthetic six-slice axial series whose files differ only in the sign of SpacingBetweenSlices (0018,0088), read in the default GetGDCMSeriesFileNames order.

    SimpleITK ITK SBS = +1 SBS = −1 SBS = −1 with ForceOrthogonalDirectionOff()
    2.3.1 5.3 +1 +1 n/a
    2.4.1 5.4 +1 −1 (wrong) n/a
    2.5.2, 2.5.3, 2.5.6 5.4 +1 −1 (wrong) +1
    3.0.0b1 6.0 +1 −1 (wrong) +1
    latest (3.0.0b1.post230) 6.0 +1 +1 +1

    Values are direction[2,2]. In the failing case the voxel planes remain in ascending ImagePositionPatient order, but the direction matrix makes their reported physical z coordinates run in the opposite direction.

    The development build is correct, but the 2.4.x and 2.5.x releases we tested, including 2.5.6 on PyPI, still reproduce the problem. The corresponding change is present on ITK main but not in the current release-5.4 version of itkImageSeriesReader.hxx.

    The failure is silent and can affect downstream tools that reorient images using the direction matrix; we observed incorrect vertebral-level labels in such a segmentation workflow. In 2.5.6, ForceOrthogonalDirectionOff() corrects this synthetic axial reproduction, though we have not validated it as a general workaround for other orientations.

    Would backporting #5357 to ITK release-5.4, followed by a SimpleITK 2.5.x release, be feasible? If not, documenting ForceOrthogonalDirectionOff() as a workaround for this case would still help. If you would prefer the backport request tracked in the ITK repository, we can open an issue there.

    Minimal synthetic reproduction (pydicom + SimpleITK, no patient data): https://gist.github.com/zhurong2020/563f974baaf33c30f910f98c4d06ebad

    Best,
    Rong Zhu
    ORCID 0009-0008-6087-0581

  14. blowekamp commented on Oct 3, 2026

    @blowekamp
    Member

    Please post here asap: InsightSoftwareConsortium/ITK#6859

  15. zhurong2020 commented on Nov 1, 2026

    @zhurong2020

    Thanks to Bradley and Hans for the fix and the backport, and to the SimpleITK maintainers for the release.

    For anyone landing here later: SimpleITK 2.5.7 is built on ITK 5.4.8, which includes InsightSoftwareConsortium/ITK#6930. With 2.5.7, the reproduction script at the top of this thread now reports a last-axis direction of -1 for the top-to-bottom file order and +1 for the reversed order, as expected; 2.5.6 still reports +1 for both. The gist from my earlier comment also passes unchanged on 2.5.7, without needing ForceOrthogonalDirectionOff().

    We also re-ran a larger synthetic set (SpacingBetweenSlices +1/-1/absent, sorted or reversed file lists, ForceOrthogonalDirection default or off, three orientations; 36 runs) and six public Philips CT series with negative SpacingBetweenSlices, read in the default GetGDCMSeriesFileNames order. All were correct on 2.5.7, while the six public series had wrong slice positions on 2.5.6.

    From our side this is resolved; I'll leave closing to the original reporter and the maintainers.

  16. added a commit that references this issue on Nov 3, 2026
  17. eliem08 commented on Nov 20, 2026

    @eliem08
    Contributor

    Hi @MMRohe and @blowekamp — I'm picking this up to close out the remaining gap.

    First, the fix itself is already in place, so there is nothing left to fix in the reader: ITK #5357 (backported as #6930 to release-5.4 / ITK 5.4.8) corrects the sign of the last direction column when ForceOrthogonalDirection is on, and SimpleITK 2.5.7 ships it — I verified with a synthetic 3-slice series matching the issue (IPP z = 70 / -187.5 / -445, axial IOP, SBS absent / +1 / -1, both file orders): 2.5.7 reports direction (0,0,-1) top-to-bottom and (0,0,+1) bottom-to-top with correct origins and physical voxel positions in all 6 runs, while 2.5.6 gets the top-to-bottom direction wrong, as reported. Thanks to @zhurong2020 for the 2.5.7 confirmation in November — that matches what I see.

    What is still missing is a regression test in SimpleITK itself: the existing DicomSeriesReader test only tolerates both behaviors (magnitude-only z-column check), so a reintroduction of this bug would not be caught. I am opening a PR that adds TEST(IO, ImageSeriesReader_DirectionFromSliceOrder) in Testing/Unit/sitkImageIOTests.cxx, pinning the corrected contract (exact origin, full direction matrix, z-spacing, and physical voxel-plane positions) for the synthetic series in both file orders and all three SpacingBetweenSlices variants.

    One honest caveat: I could not compile the C++ test here (CPU-only machine, no full SuperBuild), so the PR is explicit that CI needs to run it. The test logic was verified instead via an exact Python mirror against pip SimpleITK 2.5.7 (passes) and 2.5.6 (fails on the buggy direction, as expected).

    Once that PR lands, I believe this issue can be closed — the reader behavior is fixed in 2.5.7+ and pinned by the new test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions