Parskatt / DKM

[CVPR 2023] DKM: Dense Kernelized Feature Matching for Geometry Estimation
https://parskatt.github.io/DKM/
Other
378 stars 28 forks source link

Fix pixel coordinates bug #35

Closed travisdriver closed 1 year ago

travisdriver commented 1 year ago

Thank you for your great work and for open-sourcing your code!

I believe there is a small bug in the to_pixel_coordinates function. Specifically, consider a square image with side length 1024. Since align_corners=False is used throughout the code, where pixels are treated as squares of side length 1, -1 and 1 in the normalized grid correspond to 0 and 1024, respectively.

You correctly accounted for this in the code via torch.linspace(-1 + 1 / h, 1 - 1 / h, h) and torch.linspace(-1 + 1 / w, 1 - 1 / w, w), i.e., -1 + 1 / h corresponds to 0.5 and 1 - 1 / h corresponds to 1023.5. However, when converting these normalized coordinates back to pixels, they must be shifted left by 0.5 pixels after rescaling.

Parskatt commented 1 year ago

Hi Travis. This is not a bug, but an intentional choice of pixel grid like, e.g., colmap. That is, we say the center of the top left pixel is (0.5, 0.5).

travisdriver commented 1 year ago

Ah ok, I was getting out of bounds errors when using another library which was using a different convention. Sorry for the confusion, and thank you for the explanation!

Parskatt commented 1 year ago

No worries, I should probably make this more clear :) It's a super common cause of confusion.