Rescale a depth image tensor. Args: depth: The depth tensor to transform. depth_min: The min depth to scale depth to. depth_max: The max clamp depth after scaling. Returns: The rescaled depth and rescale factor.
(
depth: torch.Tensor, depth_min: float = 1.0, depth_max: float = 1e2
)
| 279 | |
| 280 | |
| 281 | def _rescale_depth( |
| 282 | depth: torch.Tensor, depth_min: float = 1.0, depth_max: float = 1e2 |
| 283 | ) -> tuple[torch.Tensor, torch.Tensor]: |
| 284 | """Rescale a depth image tensor. |
| 285 | |
| 286 | Args: |
| 287 | depth: The depth tensor to transform. |
| 288 | depth_min: The min depth to scale depth to. |
| 289 | depth_max: The max clamp depth after scaling. |
| 290 | |
| 291 | Returns: |
| 292 | The rescaled depth and rescale factor. |
| 293 | """ |
| 294 | current_depth_min = depth.flatten(depth.ndim - 3).min(dim=-1).values |
| 295 | depth_factor = depth_min / (current_depth_min + 1e-6) |
| 296 | depth = (depth * depth_factor[..., None, None, None]).clamp(max=depth_max) |
| 297 | return depth, depth_factor |