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

Function unnormalize_depth

diff2flow/dataset/depth_preprocessing.py:190–224  ·  view source on GitHub ↗

Unnormalize depth map from [-1, 1] to actual depth values. Args: depth: Torch tensor depth map in range [-1, 1]. q_min: Min quantile used for normalization (planar depths). q_max: Max quantile used for normalization (planar depths). normalization_fn: Function

(depth, q_min, q_max, normalization_fn: str = 'log')

Source from the content-addressed store, hash-verified

188
189
190def unnormalize_depth(depth, q_min, q_max, normalization_fn: str = 'log'):
191 """
192 Unnormalize depth map from [-1, 1] to actual depth values.
193 Args:
194 depth: Torch tensor depth map in range [-1, 1].
195 q_min: Min quantile used for normalization (planar depths).
196 q_max: Max quantile used for normalization (planar depths).
197 normalization_fn: Function used for normalization (log,
198 inverse, identity).
199 Returns:
200 Unnormalized depth map in range [0, inf].
201 """
202 # First of all, unnormalize from [-1,1] to [0,1]
203 depth = depth / 2 + 0.5
204
205 # Then, unnormalize from [0,1] using the corresponding quantile
206 if normalization_fn == "log":
207 q_min = torch.log(torch.tensor(q_min))
208 q_max = torch.log(torch.tensor(q_max))
209 elif normalization_fn == "inverse":
210 warnings.warn("Inverse normalization is not working well yet!")
211 q_min = 1.0 / q_min
212 q_max = 1.0 / q_max
213 depth = depth * (q_max - q_min) + q_min
214
215 # Finally, unnormalize using the function
216 if normalization_fn == "identity":
217 return depth
218 elif normalization_fn == "log":
219 return torch.exp(depth)
220 elif normalization_fn == "inverse":
221 depth = depth.clamp(1e-6, 1e6)
222 return 1.0 / depth
223 else:
224 raise ValueError(f"Unknown normalization function: {normalization_fn}")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected