MCPcopy Create free account
hub / github.com/QWTforGithub/T2LDM / convert_depth

Function convert_depth

utils/common.py:2056–2078  ·  view source on GitHub ↗

Convert metric depth in [0, `max_depth`] to normalized depth in [0, 1].

(
    metric: torch.Tensor,
    mask: torch.Tensor | None = None,
    image_format="log_depth",
    min_depth=0.01,
    max_depth=50.0
)

Source from the content-addressed store, hash-verified

2054 return mask.float()
2055
2056def convert_depth(
2057 metric: torch.Tensor,
2058 mask: torch.Tensor | None = None,
2059 image_format="log_depth",
2060 min_depth=0.01,
2061 max_depth=50.0
2062) -> torch.Tensor:
2063 """
2064 Convert metric depth in [0, `max_depth`] to normalized depth in [0, 1].
2065 """
2066
2067 if mask is None:
2068 mask = get_mask(metric)
2069 if image_format == "log_depth":
2070 normalized = torch.log2(metric + 1 + 0.0001) / np.log2(max_depth + 1 + 0.0001)
2071 elif image_format == "inverse_depth":
2072 normalized = min_depth / metric.add(1e-8)
2073 elif image_format == "depth":
2074 normalized = metric.div(max_depth)
2075 else:
2076 raise ValueError
2077 normalized = normalized.clamp(0, 1) * mask
2078 return normalized
2079
2080def revert_depth(
2081 normalized: torch.Tensor,

Callers

nothing calls this directly

Calls 1

get_maskFunction · 0.85

Tested by

no test coverage detected