Predict images from gaussians. Args: gaussians: The Gaussians to render. extrinsics: The extrinsics of the camera to render to in OpenCV format. intrinsics: The intriniscs of the camera to render to in OpenCV format. image_width: The desired o
(
self,
gaussians: Gaussians3D,
extrinsics: torch.Tensor,
intrinsics: torch.Tensor,
image_width: int,
image_height: int,
)
| 70 | self.low_pass_filter_eps = low_pass_filter_eps |
| 71 | |
| 72 | def forward( |
| 73 | self, |
| 74 | gaussians: Gaussians3D, |
| 75 | extrinsics: torch.Tensor, |
| 76 | intrinsics: torch.Tensor, |
| 77 | image_width: int, |
| 78 | image_height: int, |
| 79 | ) -> RenderingOutputs: |
| 80 | """Predict images from gaussians. |
| 81 | |
| 82 | Args: |
| 83 | gaussians: The Gaussians to render. |
| 84 | extrinsics: The extrinsics of the camera to render to in OpenCV format. |
| 85 | intrinsics: The intriniscs of the camera to render to in OpenCV format. |
| 86 | image_width: The desired output image width. |
| 87 | image_height: The desired output image height. |
| 88 | """ |
| 89 | batch_size = len(gaussians.mean_vectors) |
| 90 | outputs_list: list[RenderingOutputs] = [] |
| 91 | |
| 92 | for ib in range(batch_size): |
| 93 | colors, alphas, meta = gsplat.rendering.rasterization( |
| 94 | means=gaussians.mean_vectors[ib], |
| 95 | quats=gaussians.quaternions[ib], |
| 96 | scales=gaussians.singular_values[ib], |
| 97 | opacities=gaussians.opacities[ib], |
| 98 | colors=gaussians.colors[ib], |
| 99 | viewmats=extrinsics[ib : ib + 1], |
| 100 | Ks=intrinsics[ib : ib + 1, :3, :3], |
| 101 | width=image_width, |
| 102 | height=image_height, |
| 103 | render_mode="RGB+D", |
| 104 | rasterize_mode="classic", |
| 105 | absgrad=False, |
| 106 | packed=False, |
| 107 | eps2d=self.low_pass_filter_eps, |
| 108 | ) |
| 109 | |
| 110 | rendered_color = colors[..., 0:3].permute([0, 3, 1, 2]) |
| 111 | rendered_depth_unnormalized = colors[..., 3:4].permute([0, 3, 1, 2]) |
| 112 | rendered_alpha = alphas.permute([0, 3, 1, 2]) |
| 113 | |
| 114 | # Compose with background color. |
| 115 | rendered_color = self.compose_with_background( |
| 116 | rendered_color, rendered_alpha, self.background_color |
| 117 | ) |
| 118 | |
| 119 | # Colorspace conversion. |
| 120 | if self.color_space == "sRGB": |
| 121 | pass |
| 122 | elif self.color_space == "linearRGB": |
| 123 | rendered_color = cs_utils.linearRGB2sRGB(rendered_color) |
| 124 | else: |
| 125 | ValueError("Unsupported ColorSpace type.") |
| 126 | |
| 127 | # splats: (B, N, 10) |
| 128 | cov2d = self._conics_to_covars2d(meta["conics"]) |
| 129 | # Set the cov2d of invisible splats to 1 to avoid nan in condition number calculation.. |
nothing calls this directly
no test coverage detected