Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warping even sized matrices in the nearest mode causes 0 to apear in the last row/column #862

Closed
magnux opened this issue Jan 20, 2021 · 2 comments
Labels
bug 馃悰 Something isn't working module: geometry

Comments

@magnux
Copy link

magnux commented Jan 20, 2021

馃悰 Bug

Warping even sized matrices in the nearest mode causes 0 to apear in the last row/column.
The odd sized matrices are handled correctly, so it seems some rounding or border case issue.

To Reproduce

import torch
import kornia

torch.manual_seed(0)
M = torch.eye(3).unsqueeze(0)

dsize = (3, 3)
src = torch.ones(1, 3, *dsize)
warper = kornia.HomographyWarper(*dsize, mode='nearest')
warper.precompute_warp_grid(M)

print(warper(src))

dsize = (4, 4)
src = torch.ones(1, 3, *dsize)
warper = kornia.HomographyWarper(*dsize, mode='nearest')
warper.precompute_warp_grid(M)

print(warper(src))

Results:

tensor([[[[1., 1., 1.],
          [1., 1., 1.],
          [1., 1., 1.]],

         [[1., 1., 1.],
          [1., 1., 1.],
          [1., 1., 1.]],

         [[1., 1., 1.],
          [1., 1., 1.],
          [1., 1., 1.]]]])

tensor([[[[1., 1., 1., 0.],
          [1., 1., 1., 0.],
          [1., 1., 1., 0.],
          [0., 0., 0., 0.]],

         [[1., 1., 1., 0.],
          [1., 1., 1., 0.],
          [1., 1., 1., 0.],
          [0., 0., 0., 0.]],

         [[1., 1., 1., 0.],
          [1., 1., 1., 0.],
          [1., 1., 1., 0.],
          [0., 0., 0., 0.]]]])

Expected behavior

Results:

tensor([[[[1., 1., 1.],
          [1., 1., 1.],
          [1., 1., 1.]],

         [[1., 1., 1.],
          [1., 1., 1.],
          [1., 1., 1.]],

         [[1., 1., 1.],
          [1., 1., 1.],
          [1., 1., 1.]]]])

tensor([[[[1., 1., 1., 1.],
          [1., 1., 1., 1.],
          [1., 1., 1., 1.],
          [1., 1., 1., 1.]],

         [[1., 1., 1., 1.],
          [1., 1., 1., 1.],
          [1., 1., 1., 1.],
          [1., 1., 1., 1.]],

         [[1., 1., 1., 1.],
          [1., 1., 1., 1.],
          [1., 1., 1., 1.],
          [1., 1., 1., 1.]]]])

Environment

kornia 0.4.0

@edgarriba
Copy link
Member

hi @magnux , thanks for reporting this issue.

I believe that this is related to #747 that refers to the align_corners flag for the grid_sample function. Check my comment here: #747 (comment)

Ideally we should find a proper configuration for aligning corners. /cc @pmeier was trying to normalize this across different functions too.

@edgarriba edgarriba added bug 馃悰 Something isn't working module: geometry labels Jan 20, 2021
@magnux
Copy link
Author

magnux commented Jan 20, 2021

Calling HomographyWarper with align_corners=True indeed solves the issue.
It seems related with #747

@kornia kornia locked and limited conversation to collaborators Jan 20, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug 馃悰 Something isn't working module: geometry
Projects
None yet
Development

No branches or pull requests

2 participants