From 5f7afbb29ed59bf810884b2d5d0ad4e2d94f772c Mon Sep 17 00:00:00 2001 From: Jean-Christophe Ruel Date: Tue, 14 May 2024 18:35:03 -0400 Subject: [PATCH 1/2] fix: Fix docs for get_projection_transform The scale_z should be positive in the K matrix. Minimal example: https://colab.research.google.com/drive/1od4ql8Y2P0d2_-JBxkLp4Yu9z_M_QRy6?usp=sharing --- pytorch3d/renderer/cameras.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch3d/renderer/cameras.py b/pytorch3d/renderer/cameras.py index d3d4ff24..ce86bff2 100644 --- a/pytorch3d/renderer/cameras.py +++ b/pytorch3d/renderer/cameras.py @@ -915,7 +915,7 @@ def get_projection_transform(self, **kwargs) -> Transform3d: K = [ [scale_x, 0, 0, -mid_x], [0, scale_y, 0, -mix_y], - [0, 0, -scale_z, -mid_z], + [0, 0, scale_z, -mid_z], [0, 0, 0, 1], ] """ From b59d71004b34de330e711dbd1b3cc56818c25e84 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Ruel Date: Mon, 27 May 2024 16:06:38 -0400 Subject: [PATCH 2/2] Fix z normalization to [0, 1] --- pytorch3d/renderer/cameras.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pytorch3d/renderer/cameras.py b/pytorch3d/renderer/cameras.py index ce86bff2..3f411525 100644 --- a/pytorch3d/renderer/cameras.py +++ b/pytorch3d/renderer/cameras.py @@ -886,8 +886,8 @@ def compute_projection_matrix( # NOTE: This maps the z coordinate to the range [0, 1] and replaces the # the OpenGL z normalization to [-1, 1] - K[:, 2, 2] = z_sign * (1.0 / (zfar - znear)) * scale_xyz[:, 2] - K[:, 2, 3] = -znear / (zfar - znear) + K[:, 2, 2] = z_sign * (2.0 / (zfar - znear)) * scale_xyz[:, 2] + K[:, 2, 3] = -2*znear / (zfar - znear) return K @@ -910,7 +910,7 @@ def get_projection_transform(self, **kwargs) -> Transform3d: scale_z = 2 / (far-near) mid_x = (max_x + min_x) / (max_x - min_x) mix_y = (max_y + min_y) / (max_y - min_y) - mid_z = (far + near) / (far - near) + mid_z = 2 * near / (far - near) K = [ [scale_x, 0, 0, -mid_x],