Skip to content

learn2reg_nlst_paired_lung_ct.ipynb keypoints warping #2021

Closed

Description

@coolteemf

Hi,
I'm working on a new registration method, and decided to use learn2reg_nlst_paired_lung_ct.ipynb as a base.
However, the conversion from keypoints from voxel coordinates to warping coordinates in the range [-1, 1] seems incorrect to me.
It is done like this (in the forward function):

offset = torch.as_tensor(fixed_image.shape[-3:]).to(fixed_keypoints.device) / 2
offset = offset[None][None]
ddf_keypoints = torch.flip((fixed_keypoints - offset) / offset, (-1,))

But in the Warp class of Monai, the conversion is done like this:

for i, dim in enumerate(grid.shape[1:-1]):
    grid[..., i] = grid[..., i] * 2 / (dim - 1) - 1
index_ordering: list[int] = list(range(spatial_dims - 1, -1, -1))
grid = grid[..., index_ordering]  # z, y, x -> x, y, z

Which seems correct to me, since voxel coordinates should max out at dim - 1 for indexing.

The two are almost equivalent, except that in the notebook, image.shape is used and not image.shape - 1, so I think the notebook is wrong.
Feel free to correct me if I'm wrong, because I'm lacking info on what exactly are those keypoints and how they were obtained.

Activity

  1. ericspod commented on Sep 5, 2025

    @ericspod
    Member

    Hi @coolteemf it's possible the notebook is incorrect, could you provide a correcting code snippet? @nvahmadi could you have a look at this issue? Also the images the notebook used in the description are no longer available, would have these elsewhere? Thanks!

  2. flecomet commented on Sep 5, 2025

    @flecomet

    Hi @ericspod
    correcting code snippet:

    offset = (torch.as_tensor(fixed_image.shape[-3:]).to(fixed_keypoints.device) - 1) / 2
    offset = offset[None][None]
    ddf_keypoints = torch.flip((fixed_keypoints - offset) / offset, (-1,))
    

    I added the -1 to the offset computation, which is now equivalent to the dim - 1 in the Warp function

  3. hmeixx commented on Sep 12, 2026

    @hmeixx
    Contributor

    Hi @ericspod, I’m interested in working on this issue. I noticed that it has been inactive for a while. Is this issue still available to work on?

    If so, I’d be happy to investigate the keypoint coordinate convention and verify whether the proposed dim - 1 fix is correct. Thanks!

  4. added a commit that references this issue on Sep 15, 2026
    e18d140
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions