Skip to content

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

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

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

Conversation

@eliem08

@eliem08 eliem08 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Replaces #2820 — same diff, re-committed with a shorter subject to satisfy the 78-character commit-message limit.

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]

@blowekamp
blowekamp self-requested a review November 20, 2026 14:17

@blowekamp blowekamp left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding this test.

This PR contains what appears to be excessive AI prose. The first line of the commit message should be very concise, we don't place an issue number in the commit message. Details and references can go in the body of the commit message.

The inline comments are too verbose they should describe "what the code does", not detail the whole issue or describe old behavior.

P.S. We do have a minimal AGENTS.md file in main that might help, but there is not one in the release branch right now.

@eliem08

eliem08 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

You're right. Sorry, that was my sloppy writing, not the test's fault. I rewrote it: short subject with no issue number, the references moved into the commit body, and the comments now just say what the test does. Also ran clang-format, so the lint failure is gone. The cleaned-up version is in #2822. Thanks for catching it.

@eliem08

eliem08 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favour of #2822.

@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

2 participants