Skip to content

ENH: Add notebook example of Elastix-MONAI affine bridge - #193

Draft
ntatsisk wants to merge 2 commits into
InsightSoftwareConsortium:mainfrom
ntatsisk:notebook_monai_bridge
Draft

ntatsisk wants to merge 2 commits into
InsightSoftwareConsortium:mainfrom
ntatsisk:notebook_monai_bridge

Conversation

@ntatsisk

@ntatsisk ntatsisk commented Feb 3, 2023 •

Copy link
Copy Markdown
Collaborator

Includes an example of Elastix-MONAI affine bridge that was removed from InsightSoftwareConsortium/itk-torch-transform-bridge#6.

It will be updated/repurposed when Project-MONAI/MONAI#5897 is merged into MONAI.

Also related to: #126

Update

Project-MONAI/MONAI#5897 was merged in February 2023, and the ITK-MONAI affine bridge now ships with MONAI as monai.data.itk_torch_bridge. The notebook is rewritten to use it and renumbered to examples/ITK_Example27_Elastix_affine_MONAI_resample.ipynb, rebased on current main. The original commit is kept.

  • It registers the 3D lung CT pair from examples/data with an Elastix affine transform. That pair has different sizes and origins and anisotropic spacing. The previous real_*.nii.gz files were never added to the repository.
  • itk_to_monai_affine converts the Elastix parameters, and MONAI's Affine resamples the moving image onto the fixed image grid. metatensor_to_itk_image converts the result back to ITK.
  • The notebook asserts that the MONAI result matches the Elastix result image (maximum absolute difference 6.1e-5, float32 precision), so the nbmake CI job checks the bridge.
  • In MONAI 1.6.1, itk_to_monai_affine(reference_image=...) gives a wrong affine when the two images differ in size. The notebook composes the fixed-to-moving grid mapping from get_itk_image_center instead. The upstream fix is Fix itk_to_monai_affine reference_image for images of different sizes Project-MONAI/MONAI#9158; once it is released, the notebook can pass reference_image=fixed_image directly.

🤖 Generated with Claude Code

@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

ntatsisk and others added 2 commits October 8, 2026 12:49
…_bridge

The ITK-MONAI affine bridge now ships with MONAI as
monai.data.itk_torch_bridge, so use it instead of the unpublished
itk_torch_affine_matrix_bridge module, and register the 3D lung CT
images in examples/data instead of the missing real_*.nii.gz files.

The fixed and moving lung images differ in size, and as of MONAI 1.6
itk_to_monai_affine(reference_image=...) takes both grid centers from
the reference image size. Compose the fixed-to-moving grid mapping from
get_itk_image_center instead, which matches the reference_image path
for equally sized images and reproduces the Elastix result within
float32 precision here.

Convert the MONAI output back with metatensor_to_itk_image and assert
the voxel match, so the nbmake CI job checks the bridge. Number the
notebook 27, the next free example number.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

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