Skip to content

fix(compare-images): collapse the preview slice direction with Guess - #1582

Merged
thewtex merged 2 commits into
InsightSoftwareConsortium:mainfrom
vboussot:fix/compare-images-direction-collapse
Aug 18, 2026
Merged

fix(compare-images): collapse the preview slice direction with Guess#1582
thewtex merged 2 commits into
InsightSoftwareConsortium:mainfrom
vboussot:fix/compare-images-direction-collapse

Conversation

@vboussot

@vboussot vboussot commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Closes #1579.

compare-double-images extracts a middle 2D slice of the difference image for a
rescaled preview, with SetDirectionCollapseToSubmatrix(). That mode throws when
the collapsed sub-matrix is singular, which it is for the axis permutations that
are normal in 3D medical images. The NRRD space directions from the report,
(0,1,0) (0,0,-1) (-1.3,0,0), collapse to a 2x2 with determinant 0, so comparing
such an image against itself aborted the module.

Guess keeps the sub-matrix when it is valid, so images that work today are
unaffected, and falls back to the identity otherwise. The slice only feeds a
preview, so its direction carries no meaning either way.

Verification

Isolated natively first, on the extract alone:

direction (rotated):        collapsed 2x2 determinant: 0
  SubMatrix  identity ok    rotated THROWS "Invalid submatrix"
  Guess      identity ok    rotated ok
  Identity   identity ok    rotated ok

Then end to end, rebuilding the WASI module and swapping only the .wasm in an
otherwise identical environment, using the reproduction from the issue:

published 5.4.1    identity OK   rotated THREW Trap
patched            identity OK   rotated OK   almostEqual=True

The new test_compare_images_direction self-compares over identity, permuted
and flipped directions; it fails on the current module and passes on the patched
one. No test exercised a non-identity 3D direction before.

Note the package's existing ctest targets fail on this tree both before and
after this change: the test:data:download tarball is pinned to
itk-wasm-v1.0.0-b.171 and no longer matches the pipelines, giving an
out-of-bounds read. That looks like a separate issue.

@vboussot
vboussot force-pushed the fix/compare-images-direction-collapse branch from bc98dec to a819f9f Compare August 6, 2026 15:21
@vboussot

vboussot commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

CI note: the only real failure is itkwasm-python (windows-2022, 11, compare-images), the other red jobs are fail-fast cancellations.

The two new permuted tests run against the committed .wasi.wasm, which CI only rebuilds on ubuntu-24.04, so windows and macOS still test the pre-fix module. Locally I get 12 passed with the module rebuilt from this branch, and the same 2 failures with the committed one, so this needs a compare-images rebuild and release like #1581.

@vboussot
vboussot force-pushed the fix/compare-images-direction-collapse branch from a819f9f to 568fa47 Compare August 11, 2026 14:42
compare-double-images extracts a middle 2D slice of the difference image for a
rescaled preview, with SetDirectionCollapseToSubmatrix(). That mode throws when
the collapsed sub-matrix is singular, which it is for the axis permutations that
are normal in 3D medical images: NRRD space directions (0,1,0) (0,0,-1)
(-1.3,0,0) collapse to a 2x2 with determinant 0. Comparing such an image against
itself therefore aborted the module.

Guess keeps the sub-matrix when it is valid, so images that work today are
unaffected, and falls back to the identity otherwise. The slice only feeds a
preview, so its direction carries no meaning either way.

Adds tests over identity, permuted and flipped directions, covering both a
self-comparison and a single-voxel difference so the path is exercised rather
than merely silenced.

Closes InsightSoftwareConsortium#1579
@vboussot
vboussot force-pushed the fix/compare-images-direction-collapse branch from 568fa47 to 2cc0057 Compare August 13, 2026 15:40
@thewtex

thewtex commented Aug 13, 2026

Copy link
Copy Markdown
Member

…module

The Windows and macOS Python jobs test the wasm binary committed in
wasm_modules rather than rebuilding it, so the direction-collapse fix
needs the regenerated module alongside the source change. Built with
docker.io/itkwasm/wasi:latest; the new direction tests pass against it.
@thewtex
thewtex merged commit f2195c9 into InsightSoftwareConsortium:main Aug 18, 2026
74 of 109 checks passed
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.

compare-images: comparing 3D images with a non-identity direction throws

2 participants