Convert depth maps to surface normals Args: depths: Depth maps [..., H, W, 1] camtoworlds: Camera-to-world transformation matrices [..., 4, 4] Ks: Camera intrinsics [..., 3, 3] z_depth: Whether the depth is in z-depth (True) or ray depth (False) Returns:
(
depths: Tensor, camtoworlds: Tensor, Ks: Tensor, z_depth: bool = True
)
| 106 | |
| 107 | |
| 108 | def depth_to_normal( |
| 109 | depths: Tensor, camtoworlds: Tensor, Ks: Tensor, z_depth: bool = True |
| 110 | ) -> Tensor: |
| 111 | """Convert depth maps to surface normals |
| 112 | |
| 113 | Args: |
| 114 | depths: Depth maps [..., H, W, 1] |
| 115 | camtoworlds: Camera-to-world transformation matrices [..., 4, 4] |
| 116 | Ks: Camera intrinsics [..., 3, 3] |
| 117 | z_depth: Whether the depth is in z-depth (True) or ray depth (False) |
| 118 | |
| 119 | Returns: |
| 120 | normals: Surface normals in the world coordinate system [..., H, W, 3] |
| 121 | """ |
| 122 | points = depth_to_points(depths, camtoworlds, Ks, z_depth=z_depth) # [..., H, W, 3] |
| 123 | dx = torch.cat( |
| 124 | [points[..., 2:, 1:-1, :] - points[..., :-2, 1:-1, :]], dim=-3 |
| 125 | ) # [..., H-2, W-2, 3] |
| 126 | dy = torch.cat( |
| 127 | [points[..., 1:-1, 2:, :] - points[..., 1:-1, :-2, :]], dim=-2 |
| 128 | ) # [..., H-2, W-2, 3] |
| 129 | normals = F.normalize(torch.cross(dx, dy, dim=-1), dim=-1) # [..., H-2, W-2, 3] |
| 130 | normals = F.pad(normals, (0, 0, 1, 1, 1, 1), value=0.0) # [..., H, W, 3] |
| 131 | return normals |
| 132 | |
| 133 | |
| 134 | def get_projection_matrix(znear, zfar, fovX, fovY, device="cuda"): |
no test coverage detected