nerfstudio-project / nerfstudio

A collaboration friendly studio for NeRFs
https://docs.nerf.studio
Apache License 2.0
9.55k stars 1.3k forks source link

Training using cropped images #2271

Open hdacnw opened 1 year ago

hdacnw commented 1 year ago

I am trying to train with some images cropped from a single large image using nerfacto. I changed height, width and principal points (cx and cy) for each cropped image in transform.json (nerfstudio data format) using

cropped = source[y0:y1, x0:x1]
cx' = cx - x0
cy' = cy - y0  

extrinsics and focal length remain the same. However, aspect ratios of visualized images in the viewer are modified (images are stretched in the x/y direction accordingly) and training fails. I also noticed that in https://docs.nerf.studio/en/latest/nerfology/model_components/visualize_cameras.html cx and cy are defined as the number of pixels in the x/y dimension instead of principal point x/y in https://docs.nerf.studio/en/latest/quickstart/data_conventions.html. Is there something going wrong and what can I do to correct it?

Screenshots Screenshot from 2023-07-25 02-06-35

kerrj commented 1 year ago

I believe that focal length in nerfstudio is defined in terms of pixel units, so you might also need to rescale the focal length to match the new height/width. You should double check this by looking at the scale of the fx/fy (if they're large >>10 then they're probably in pixels). If that doesn't work there could be a lot of places a small math bug could happen, it might be easier to just crop the images and reprocess with colmap to save the headache.

hdacnw commented 7 months ago

I believe that focal length in nerfstudio is defined in terms of pixel units, so you might also need to rescale the focal length to match the new height/width. You should double check this by looking at the scale of the fx/fy (if they're large >>10 then they're probably in pixels). If that doesn't work there could be a lot of places a small math bug could happen, it might be easier to just crop the images and reprocess with colmap to save the headache.

I've tried to apply crop only i.e. no change in focal length so I'm only changing cx and cy, but still only at ground truth views I can see reasonable rendering. Do you know what I should check next? Thanks! @kerrj