Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

down right back to right up back conversion in llff.py #58

Closed
hturki opened this issue Feb 8, 2021 · 2 comments
Closed

down right back to right up back conversion in llff.py #58

hturki opened this issue Feb 8, 2021 · 2 comments

Comments

@hturki
Copy link

hturki commented Feb 8, 2021

Describe the bug
I'm trying to make sure that I understand the purpose of https://github.com/kwea123/nerf_pl/blob/dev/datasets/llff.py#L198. In particular, we're changing the coordinate system of the rotation matrix R but not of the translation vector, which remains in "down right back" coordinates - is that intentional?

Also bmild/nerf#34 suggests that this is mainly intended for forward facing scenes where we're using NDC, but if I'm interpreting the code correctly this transformation still happens for 360 scenes. Is that intentional and desired behavior?

Which branch you use
dev

@kwea123
Copy link
Owner

kwea123 commented Feb 9, 2021

This is not specific to NDC, but for all scenes constructed using COLMAP, which is desired behavior. Actually this conversion has relation with this part:

def get_ray_directions(H, W, focal):
"""
Get ray directions for all pixels in camera coordinate.
Reference: https://www.scratchapixel.com/lessons/3d-basic-rendering/
ray-tracing-generating-camera-rays/standard-coordinate-systems
Inputs:
H, W, focal: image height, width and focal length
Outputs:
directions: (H, W, 3), the direction of the rays in camera coordinate
"""
grid = create_meshgrid(H, W, normalized_coordinates=False)[0]
i, j = grid.unbind(-1)
# the direction here is without +0.5 pixel centering as calibration is not so accurate
# see https://github.com/bmild/nerf/issues/24
directions = \
torch.stack([(i-W/2)/focal, -(j-H/2)/focal, -torch.ones_like(i)], -1) # (H, W, 3)
return directions

When we generate camera rays, the current code assumes "right up back" camera coordinate. Take the upper left (0, 0) pixel for example, its ray will have direction in (-x, +y, -z) under this code.

That means you can omit the coordinate conversion, but if you do so you have to rewrite the get_ray_directions function to correctly generate rays in your coordinate system. Btw, the translation vector has nothing to do here, since it's the camera's position in world coordinate, so it won't change. Remember that we are changing how is the camera rotated w.r.t. the world only.

The author mentioned NDC because this conversion is indispensable for the reasons he stated in that post. 360 scenes do not necessary require this conversion, but having the same conversion leads to same code and more conciseness, so I adopted this conversion for both settings.

@kwea123 kwea123 closed this as completed Feb 9, 2021
@hturki
Copy link
Author

hturki commented Feb 9, 2021

Thanks for the clarification. Just to confirm, this repo doesn't actually do the alternate pose conversion for spheric poses detailed in https://github.com/bmild/nerf/blob/55d8b00244d7b5178f4d003526ab6667683c9da9/load_llff.py#L184 (and just calls the same center_poses method for both forward-facing and 360 scenes?)

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

No branches or pull requests

2 participants