Repository navigation
Commit e18d140
Fix NLST keypoint warping coordinates (#2073)
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:
```python
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:
```text
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
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Avoid including large-size files in the PR.
- [x] Clean up long text outputs from code cells in the notebook.
- [x] For security purposes, please check the contents and remove any
sensitive info such as user names and private key.
- [x] 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.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Corrected keypoint displacement sampling to align with PyTorch’s
corner-aligned coordinate system, improving registration accuracy and
consistency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Signed-off-by: mei <hmeixx@gmail.com>
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>1 parent 189543c commit e18d140
1 file changed
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
660 | 660 | | |
661 | 661 | | |
662 | 662 | | |
663 | | - | |
| 663 | + | |
664 | 664 | | |
665 | 665 | | |
666 | 666 | | |
667 | | - | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
668 | 672 | | |
669 | 673 | | |
670 | 674 | | |
| |||
0 commit comments