MCPcopy Create free account
hub / github.com/Ropedia/SpatialBench / lstsq_alignment

Function lstsq_alignment

benchmark/evaluation/alignment.py:33–58  ·  view source on GitHub ↗

Least-squares affine alignment: gt ≈ s * pred + t. Args: pred_depth: (H, W) gt_depth: (H, W) valid_mask: (H, W) bool Returns: aligned_pred: (H, W) s: float, scale t: float, offset

(pred_depth, gt_depth, valid_mask)

Source from the content-addressed store, hash-verified

31
32
33def lstsq_alignment(pred_depth, gt_depth, valid_mask):
34 """Least-squares affine alignment: gt ≈ s * pred + t.
35
36 Args:
37 pred_depth: (H, W)
38 gt_depth: (H, W)
39 valid_mask: (H, W) bool
40
41 Returns:
42 aligned_pred: (H, W)
43 s: float, scale
44 t: float, offset
45 """
46 pred_valid = pred_depth[valid_mask].flatten()
47 gt_valid = gt_depth[valid_mask].flatten()
48
49 if len(pred_valid) < 2:
50 return pred_depth.copy(), 1.0, 0.0
51
52 # Build [pred, 1] @ [s, t]^T = gt
53 A = np.stack([pred_valid, np.ones_like(pred_valid)], axis=1)
54 result = np.linalg.lstsq(A, gt_valid, rcond=None)
55 s, t = result[0]
56
57 aligned_pred = pred_depth * s + t
58 return aligned_pred, float(s), float(t)
59
60
61def procrustes_alignment(pred_poses, gt_poses):

Callers

nothing calls this directly

Calls 1

copyMethod · 0.80

Tested by

no test coverage detected