MCPcopy
hub / github.com/apple/ml-depth-pro / nms_horizontal

Function nms_horizontal

src/depth_pro/eval/boundary_metrics.py:29–50  ·  view source on GitHub ↗

Apply Non-Maximum Suppression (NMS) horizontally on the given ratio matrix. Args: ---- ratio (np.ndarray): Input ratio matrix. threshold (float): Threshold for NMS. Returns: ------- np.ndarray: Binary mask after applying NMS.

(ratio: np.ndarray, threshold: float)

Source from the content-addressed store, hash-verified

27
28
29def nms_horizontal(ratio: np.ndarray, threshold: float) -> np.ndarray:
30 """Apply Non-Maximum Suppression (NMS) horizontally on the given ratio matrix.
31
32 Args:
33 ----
34 ratio (np.ndarray): Input ratio matrix.
35 threshold (float): Threshold for NMS.
36
37 Returns:
38 -------
39 np.ndarray: Binary mask after applying NMS.
40
41 """
42 mask = np.zeros_like(ratio, dtype=bool)
43 r, c = np.nonzero(ratio > threshold)
44 if len(r) == 0:
45 return mask
46 for ids in connected_component(r, c):
47 values = [ratio[r[i], c[i]] for i in ids]
48 mi = np.argmax(values)
49 mask[r[ids[mi]], c[ids[mi]]] = True
50 return mask
51
52
53def nms_vertical(ratio: np.ndarray, threshold: float) -> np.ndarray:

Callers 2

nms_verticalFunction · 0.85
fgbg_depth_thinnedFunction · 0.85

Calls 1

connected_componentFunction · 0.85

Tested by

no test coverage detected