MCPcopy Create free account
hub / github.com/JasonLSC/GSCodec_Studio / depth_to_normal

Function depth_to_normal

gsplat/utils.py:108–131  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

106
107
108def 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
134def get_projection_matrix(znear, zfar, fovX, fovY, device="cuda"):

Callers 2

rasterization_2dgsFunction · 0.85

Calls 1

depth_to_pointsFunction · 0.85

Tested by

no test coverage detected