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

Function normals_edge

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

Compute the edge mask from normal map. Args: normal (np.ndarray): shape (..., height, width, 3), normal map tol (float): tolerance in degrees Returns: edge (np.ndarray): shape (..., height, width) of dtype torch.bool

(normals: np.ndarray, tol: float, kernel_size: int = 3, mask: np.ndarray = None)

Source from the content-addressed store, hash-verified

159
160@no_warnings(category=RuntimeWarning)
161def normals_edge(normals: np.ndarray, tol: float, kernel_size: int = 3, mask: np.ndarray = None) -> np.ndarray:
162 """
163 Compute the edge mask from normal map.
164
165 Args:
166 normal (np.ndarray): shape (..., height, width, 3), normal map
167 tol (float): tolerance in degrees
168
169 Returns:
170 edge (np.ndarray): shape (..., height, width) of dtype torch.bool
171 """
172 assert normals.ndim >= 3 and normals.shape[-1] == 3, "normal should be of shape (..., height, width, 3)"
173 normals = normals / (np.linalg.norm(normals, axis=-1, keepdims=True) + 1e-12)
174
175 padding = kernel_size // 2
176 normals_window = sliding_window_2d(
177 np.pad(normals, (*([(0, 0)] * (normals.ndim - 3)), (padding, padding), (padding, padding), (0, 0)), mode='edge'),
178 window_size=kernel_size,
179 stride=1,
180 axis=(-3, -2)
181 )
182 if mask is None:
183 angle_diff = np.arccos((normals[..., None, None] * normals_window).sum(axis=-3)).max(axis=(-2, -1))
184 else:
185 mask_window = sliding_window_2d(
186 np.pad(mask, (*([(0, 0)] * (mask.ndim - 3)), (padding, padding), (padding, padding)), mode='edge'),
187 window_size=kernel_size,
188 stride=1,
189 axis=(-3, -2)
190 )
191 angle_diff = np.where(mask_window, np.arccos((normals[..., None, None] * normals_window).sum(axis=-3)), 0).max(axis=(-2, -1))
192
193 angle_diff = max_pool_2d(angle_diff, kernel_size, stride=1, padding=kernel_size // 2)
194 edge = angle_diff > np.deg2rad(tol)
195 return edge
196
197
198@no_warnings(category=RuntimeWarning)

Callers

nothing calls this directly

Calls 3

normMethod · 0.80
sliding_window_2dFunction · 0.70
max_pool_2dFunction · 0.70

Tested by

no test coverage detected