MCPcopy Create free account
hub / github.com/apple/ml-sharp / write_renderings

Function write_renderings

src/sharp/utils/gsplat.py:29–45  ·  view source on GitHub ↗

Write rendered color/depth/alpha to files.

(rendering: RenderingOutputs, output_folder: Path, filename: str)

Source from the content-addressed store, hash-verified

27
28
29def write_renderings(rendering: RenderingOutputs, output_folder: Path, filename: str):
30 """Write rendered color/depth/alpha to files."""
31 batch_size = len(rendering.color)
32 if batch_size != 1:
33 raise RuntimeError("We only support saving rendering of batch size = 1")
34
35 def _save_image_tensor(tensor: torch.Tensor, suffix: str):
36 np_array = tensor.permute(1, 2, 0).numpy()
37 io.save_image(np_array, (output_folder / filename).with_suffix(suffix))
38
39 color = (rendering.color[0].cpu() * 255.0).to(dtype=torch.uint8)
40 colorized_depth = vis.colorize_depth(rendering.depth[0], val_max=100.0)
41 colorized_alpha = vis.colorize_alpha(rendering.alpha[0])
42
43 _save_image_tensor(color, ".color.png")
44 _save_image_tensor(colorized_depth, ".depth.png")
45 _save_image_tensor(colorized_alpha, ".alpha.png")
46
47
48class GSplatRenderer(nn.Module):

Callers

nothing calls this directly

Calls 2

_save_image_tensorFunction · 0.85
toMethod · 0.80

Tested by

no test coverage detected