MCPcopy Create free account
hub / github.com/CompVis/diff2flow / ImageDepthVisualizer

Class ImageDepthVisualizer

diff2flow/visualizer.py:94–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92
93
94class ImageDepthVisualizer:
95 def __call__(self, img, depth, depth_pred) -> Image:
96 # min-max normalize depth per sample
97 depth = per_sample_min_max_normalization(depth)
98 depth_pred = per_sample_min_max_normalization(depth_pred)
99 depth = depth.mean(dim=1, keepdim=True).repeat(1, 3, 1, 1)
100 depth_pred = depth_pred.mean(dim=1, keepdim=True).repeat(1, 3, 1, 1)
101 img = img / 2 + 0.5
102 # => all three should be in shape of [b 3 h w] and [0, 1]
103
104 # concatenate along width
105 out = torch.cat([img, depth, depth_pred], dim=3)
106 out = einops.rearrange(out, "b c h w -> (b h) w c")
107 out = (out * 255).clip(0, 255).cpu().numpy().astype('uint8')
108 out = Image.fromarray(out)
109 return out

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected