Skip to content

ENH: Add Transform::ApplyToImageMetadata - #2731

Draft
blowekamp wants to merge 3 commits into
SimpleITK:releasefrom
blowekamp:backport-transform-apply-to-image-metadata
Draft

blowekamp wants to merge 3 commits into
SimpleITK:releasefrom
blowekamp:backport-transform-apply-to-image-metadata

Conversation

@blowekamp

@blowekamp blowekamp commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Backport of #2721 to the release branch.

  • Wraps ITK's itk::Transform::ApplyToImageMetadata as Transform::ApplyToImageMetadata(Image &) in SimpleITK.
  • Updates an image's origin, spacing, and direction in place (mapped through the inverse of the transform), without resampling pixel data. Throws if the transform has no inverse or its dimension does not match the image's.
  • Follows the existing pimpl dispatch pattern used by TransformPoint/TransformVector (PimpleTransformBase virtual method implemented in PimpleTransform<TTransformType>).
  • Includes the doc follow-up noting the operation is only well-defined for linear transforms.

ITK dependency (resolved)

This branch's pinned ITK (v5.4.7, see SuperBuild/External_ITK.cmake) had a null-pointer dereference in itk::Transform::ApplyToImageMetadata() for non-invertible transforms, fixed upstream on ITK main by InsightSoftwareConsortium/ITK#6583 but not present in v5.4.7. The backported TransformTest.ApplyToImageMetadata unit test exercises exactly this case (a singular AffineTransform) and segfaulted without the fix.

InsightSoftwareConsortium/ITK#6914 backported that fix to ITK's release-5.4 branch and has now merged (commit f51ee1e4fd63e435f8213556ef76e6c3b31ad04a). This branch's SuperBuild/External_ITK.cmake now pins ITK_GIT_TAG to that commit instead of v5.4.7, until it lands in a tagged v5.4.x release.

Test plan

  • Full SuperBuild configure + build (SuperBuild/, Release, BUILD_TESTING=ON, elastix disabled) succeeds.
  • Full ctest suite (549/549) passes against the updated ITK_GIT_TAG pin, including the new TransformTest.ApplyToImageMetadata.

blowekamp and others added 3 commits September 28, 2026 13:12
Wraps itk::Transform::ApplyToImageMetadata, which updates an image's
origin, spacing, and direction in place, mapped through the inverse
of the transform, without resampling pixel data.

(cherry picked from commit 18a5f84)
…orms

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
(cherry picked from commit 7bb563e)
@blowekamp
blowekamp requested review from dave3d and zivy September 29, 2026 21:51

This branch has not been deployed

No deployments
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.

2 participants