Skip to content

BUG: Add regression test for ImageSeriesReader direction from slice order (#2292) - #2820

Closed
eliem08 wants to merge 1 commit into
SimpleITK:mainfrom
eliem08:fix/dicom-series-direction-test
Closed

eliem08 wants to merge 1 commit into
SimpleITK:mainfrom
eliem08:fix/dicom-series-direction-test

Conversation

@eliem08

@eliem08 eliem08 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #2292.

The direction-matrix bug in #2292 was fixed upstream in ITK
(InsightSoftwareConsortium/ITK#5357,
backported in
ITK#6930,
shipped in SimpleITK 2.5.7): when ForceOrthogonalDirection is on (the
default), the last direction column was taken from the DICOM row/column
orientation cross product without checking its sign against the actual
slice-traversal vector, so reading a series bottom-to-top (or any order
implying negative inter-slice spacing) reported direction (0,0,-1) where
(0,0,+1) was correct, while the origin and spacing were right. The
existing DicomSeriesReader test was only adapted to tolerate both
behaviors (magnitude-only z-column check, commit 6900990); nothing in the
SimpleITK suite asserts the corrected behavior, so a reintroduction would
go unnoticed.

This adds TEST(IO, ImageSeriesReader_DirectionFromSliceOrder) in
Testing/Unit/sitkImageIOTests.cxx. It synthesizes the issue's 3-slice
axial DICOM series (Image Position (Patient) z = 70 / -187.5 / -445, Image
Orientation (Patient) = 1 0 0 / 0 1 0) with ImageFileWriter, in three
SpacingBetweenSlices variants (absent / 1 / -1), reads it
top-to-bottom and bottom-to-top, and asserts the exact origin, the full
direction matrix, z-spacing 257.5, and the physical z of the first and last
voxel planes against the ImagePositionPatient tags.

Test evidence

The C++ test itself was not compiled or run here — a full SimpleITK
SuperBuild is not feasible on the CPU-only machine used for this change, so
please let CI run it. What was verified instead is an exact Python mirror
of the test logic (same tags, same file layout, same assertions) against
pip-installed SimpleITK:

  • SimpleITK 2.5.7 (ITK 5.4.8, fixed): 0 failures — all 3
    SpacingBetweenSlices variants x both file orders pass.
  • SimpleITK 2.5.6 (ITK 5.4.7, buggy): 6 failures — top-to-bottom
    direction is (1,0,0, 0,1,0, 0,0,+1) instead of (…, -1) and the last
    voxel plane's physical z is wrong, in all 3 variants.

An independent pydicom-written reproduction of the issue geometry agrees:
2.5.7 passes 6/6 (order x SBS sign), 2.5.6 fails 3/6.

One deliberate limitation, documented in a NOTE comment in the test: the
test does not assert the SpacingBetweenSlices value written to the files.
While validating, I observed via the Python bindings that once a DICOM read
has happened in a process, later DICOM writes stamp
SpacingBetweenSlices (0018,0088) = "1" regardless of the value set on the
slice (write-only processes round-trip the value correctly). The geometry
assertions are unaffected by that — with the ITK fix the direction is
correct for every SpacingBetweenSlices value — so the test still fails on
the buggy behavior. That writer observation is separate from #2292 and is
not asserted here.

Signed-off-by: Ilyass Emssaad [email protected]

@eliem08

eliem08 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favour of the replacement PR (same diff, shorter commit subject for the ghostflow check).

@eliem08 eliem08 closed this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImageSeriesReader create an incorrect direction matrix

1 participant