Skip to content

Fix NLST keypoint warping coordinates - #2073

Merged
ericspod merged 2 commits into
Project-MONAI:mainfrom
hmeixx:fix-nlst-keypoint-warping
Sep 15, 2026
Merged

ericspod merged 2 commits into
Project-MONAI:mainfrom
hmeixx:fix-nlst-keypoint-warping

Conversation

@hmeixx

@hmeixx hmeixx commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #2021

Description

This PR fixes the keypoint coordinate normalization used when sampling the displacement field in learn2reg_nlst_paired_lung_ct.ipynb.

Previously, keypoint voxel coordinates were normalized using the image dimension:

offset = torch.as_tensor(fixed_image.shape[-3:]).to(fixed_keypoints.device) / 2

This corresponds to 2 * x / dim - 1, which does not map voxel indices [0, dim - 1] to [-1, 1].

The normalization is updated to use (dim - 1) / 2, corresponding to:

2 * x / (dim - 1) - 1

align_corners=True is also explicitly specified in F.grid_sample so that the sampling convention is consistent with this normalization and with MONAI Warp.

A small local grid_sample check confirmed that the updated normalization maps voxel centers correctly.

Checks

  • Avoid including large-size files in the PR.
  • Clean up long text outputs from code cells in the notebook.
  • For security purposes, please check the contents and remove any sensitive info such as user names and private key.
  • Ensure (1) hyperlinks and markdown anchors are working (2) use relative paths for tutorial repo files (3) put figure and graphs in the ./figure folder
  • Notebook runs automatically ./runner.sh -t <path to .ipynb file>

Local PEP 8/format checks passed with runner.sh. Notebook execution was skipped by the existing runner skip pattern.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected keypoint displacement sampling to align with PyTorch’s corner-aligned coordinate system, improving registration accuracy and consistency.

@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

@coderabbitai

coderabbitai Bot commented Sep 12, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: b5a0e6d3-1ae6-4d65-b1c0-9423bde6582f

📥 Commits

Reviewing files that changed from the base of the PR and between b3c6c99 and 2733afb.

📒 Files selected for processing (1)
  • 3d_registration/learn2reg_nlst_paired_lung_ct.ipynb

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


Walkthrough

The notebook updates keypoint coordinate normalization to use corner-aligned spatial extents and enables align_corners=True when sampling the predicted displacement field.

Changes

Keypoint warping

Layer / File(s) Summary
Corner-aligned coordinate sampling
3d_registration/learn2reg_nlst_paired_lung_ct.ipynb
Keypoint normalization now uses (dimension - 1) / 2. Displacement sampling explicitly uses align_corners=True.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 60b5e

The notebook change aligns keypoint coordinates with displacement sampling without leaving an identified merge-blocking risk.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: fixing NLST keypoint warping coordinates.
Description check ✅ Passed The description explains the coordinate normalization change, the align_corners=True setting, validation performed, and checklist status. It also states why notebook execution was skipped.
Linked Issues check ✅ Passed The change addresses issue #2021. The keypoint normalization uses (dim - 1) / 2, which maps voxel indices through the maximum index dim - 1 to [-1, 1]. F.grid_sample now sets `align_corners=Tr…
Out of Scope Changes check ✅ Passed The pull request changes only 3d_registration/learn2reg_nlst_paired_lung_ct.ipynb. The reported changes update keypoint coordinate normalization and sampling alignment, both directly required by iss…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Signed-off-by: mei <hmeixx@gmail.com>
@hmeixx
hmeixx force-pushed the fix-nlst-keypoint-warping branch from 2733afb to a815ea2 Compare September 12, 2026 10:26
@ericspod
ericspod merged commit e18d140 into Project-MONAI:main Sep 15, 2026
7 checks passed
@ericspod

Copy link
Copy Markdown
Member

HI @hmeixx thanks for this fix, it looks good to me.

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.

learn2reg_nlst_paired_lung_ct.ipynb keypoints warping

2 participants