Update NDC raysampler for non-square convention (#29)

Summary:
- Old NDC convention had xy coords in [-1,1]x[-1,1]
- New NDC convention has xy coords in [-1, 1]x[-u, u] or [-u, u]x[-1, 1]

where u > 1 is the aspect ratio of the image.

This PR fixes the NDC raysampler to use the new convention.

Partial fix for https://github.com/facebookresearch/pytorch3d/issues/868

Pull Request resolved: https://github.com/fairinternal/pytorch3d/pull/29

Reviewed By: davnov134

Differential Revision: D31926148

Pulled By: bottler

fbshipit-source-id: c6c42c60d1473b04e60ceb49c8c10951ddf03c74
This commit is contained in:
Ignacio Rocco
2021-11-05 10:28:51 -07:00
committed by Facebook GitHub Bot
parent bfeb82efa3
commit cac6cb1b78
4 changed files with 118 additions and 35 deletions

View File

@@ -159,8 +159,12 @@ class TestRenderImplicit(TestCaseMixin, unittest.TestCase):
with self.assertRaises(ValueError):
renderer(cameras=cameras, volumetric_function=bad_volumetric_function)
def test_compare_with_meshes_renderer(
self, batch_size=11, image_size=100, sphere_diameter=0.6
def test_compare_with_meshes_renderer(self):
self._compare_with_meshes_renderer(image_size=(200, 100))
self._compare_with_meshes_renderer(image_size=(100, 200))
def _compare_with_meshes_renderer(
self, image_size, batch_size=11, sphere_diameter=0.6
):
"""
Generate a spherical RGB volumetric function and its corresponding mesh
@@ -169,9 +173,7 @@ class TestRenderImplicit(TestCaseMixin, unittest.TestCase):
"""
# generate NDC camera extrinsics and intrinsics
cameras = init_cameras(
batch_size, image_size=[image_size, image_size], ndc=True
)
cameras = init_cameras(batch_size, image_size=image_size, ndc=True)
# get rand offset of the volume
sphere_centroid = torch.randn(batch_size, 3, device=cameras.device) * 0.1
@@ -179,8 +181,8 @@ class TestRenderImplicit(TestCaseMixin, unittest.TestCase):
# init the grid raysampler with the ndc grid
raysampler = NDCGridRaysampler(
image_width=image_size,
image_height=image_size,
image_width=image_size[1],
image_height=image_size[0],
n_pts_per_ray=256,
min_depth=0.1,
max_depth=2.0,
@@ -336,9 +338,11 @@ class TestRenderImplicit(TestCaseMixin, unittest.TestCase):
self.assertClose(mu_diff, torch.zeros_like(mu_diff), atol=5e-2)
self.assertClose(std_diff, torch.zeros_like(std_diff), atol=6e-2)
def test_rotating_gif(
self, n_frames=50, fps=15, image_size=(100, 100), sphere_diameter=0.5
):
def test_rotating_gif(self):
self._rotating_gif(image_size=(200, 100))
self._rotating_gif(image_size=(100, 200))
def _rotating_gif(self, image_size, n_frames=50, fps=15, sphere_diameter=0.5):
"""
Render a gif animation of a rotating sphere (runs only if `DEBUG==True`).
"""