MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / depth_aliasing

Function depth_aliasing

eval_code/recons/models/moge/utils3d/numpy/utils.py:134–158  ·  view source on GitHub ↗

Compute the map that indicates the aliasing of x depth map. The aliasing is defined as the pixels which neither close to the maximum nor the minimum of its neighbors. Args: depth (np.ndarray): shape (..., height, width), linear depth map atol (float): absolute tolerance

(depth: np.ndarray, atol: float = None, rtol: float = None, kernel_size: int = 3, mask: np.ndarray = None)

Source from the content-addressed store, hash-verified

132
133
134def depth_aliasing(depth: np.ndarray, atol: float = None, rtol: float = None, kernel_size: int = 3, mask: np.ndarray = None) -> np.ndarray:
135 """
136 Compute the map that indicates the aliasing of x depth map. The aliasing is defined as the pixels which neither close to the maximum nor the minimum of its neighbors.
137 Args:
138 depth (np.ndarray): shape (..., height, width), linear depth map
139 atol (float): absolute tolerance
140 rtol (float): relative tolerance
141
142 Returns:
143 edge (np.ndarray): shape (..., height, width) of dtype torch.bool
144 """
145 if mask is None:
146 diff_max = max_pool_2d(depth, kernel_size, stride=1, padding=kernel_size // 2) - depth
147 diff_min = max_pool_2d(-depth, kernel_size, stride=1, padding=kernel_size // 2) + depth
148 else:
149 diff_max = max_pool_2d(np.where(mask, depth, -np.inf), kernel_size, stride=1, padding=kernel_size // 2) - depth
150 diff_min = max_pool_2d(np.where(mask, -depth, -np.inf), kernel_size, stride=1, padding=kernel_size // 2) + depth
151 diff = np.minimum(diff_max, diff_min)
152
153 edge = np.zeros_like(depth, dtype=bool)
154 if atol is not None:
155 edge |= diff > atol
156 if rtol is not None:
157 edge |= diff / depth > rtol
158 return edge
159
160@no_warnings(category=RuntimeWarning)
161def normals_edge(normals: np.ndarray, tol: float, kernel_size: int = 3, mask: np.ndarray = None) -> np.ndarray:

Callers

nothing calls this directly

Calls 1

max_pool_2dFunction · 0.70

Tested by

no test coverage detected