Skip to content

Fix affine-elastic composition order - #1498

Open
ShreyanshGoyal wants to merge 1 commit into
TorchIO-project:mainfrom
ShreyanshGoyal:1491-fix-affine-elastic-order
Open

Fix affine-elastic composition order#1498
ShreyanshGoyal wants to merge 1 commit into
TorchIO-project:mainfrom
ShreyanshGoyal:1491-fix-affine-elastic-order

Conversation

@ShreyanshGoyal

Copy link
Copy Markdown

Fixes #1491.

Description

Correct the sampling-grid composition for combined affine and elastic spatial transforms. Resampling evaluates the inverse transform, so an affine-then-elastic forward transform must undo the elastic displacement before applying the affine output-to-input mapping. The previous branches implemented the opposite order.

Add an analytical regression test using a 2x affine scale and a constant one-voxel displacement. These non-commuting transforms make the expected coordinates explicit for both affine_first values.

Validation:

  • pytest -q tests/test_spatial.py (112 passed)
  • ruff check src/torchio/transforms/spatial/spatial.py tests/test_spatial.py
  • ruff format --check src/torchio/transforms/spatial/spatial.py tests/test_spatial.py
  • The new regression test fails with the production source reverted to main and passes with this fix.

Checklist

  • I have read the CONTRIBUTING docs and have a developer setup ready
  • Changes are
    • Non-breaking (would not break existing functionality)
    • Breaking (would cause existing functionality to change)
  • Tests added or modified to cover the changes
  • In-line docstrings updated
  • Documentation updated
  • This pull request is ready to be reviewed

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.

Reverse order in the RandomAffineElasticDeformation application

1 participant