test(depth_align): real z-buffer collision + drop dead var

The 2× focal-length collision test wasn't actually colliding (adjacent IR
pixels rounded to different RGB columns). 4× makes them collapse, so the
np.minimum.at reduce is now exercised. Also drop unused H_ir, W_ir.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Adriano Dal PastroandClaude Opus 4.7 committed 2026-05-11 14:28:15 +02:00
1 parent 5354c51d60
commit 810a6102fb
2 files changed
+11 -15

No files matched your search

-1
View File
@@ -45,7 +45,6 @@ def align_depth_to_rgb(
)
H_rgb, W_rgb = reg.rgb_height, reg.rgb_width
H_ir, W_ir = reg.ir_height, reg.ir_width
valid = depth_ir_mm > 0
if not valid.any():
+11 -14
View File
@@ -57,15 +57,15 @@ def test_sparse_pixels_preserved():
def test_z_buffer_keeps_closer_point():
"""When two IR pixels collide on the same RGB pixel, the smaller depth wins.
Force a collision with K_ir = 2 × K_rgb (same resolution), so adjacent IR
Force a collision with K_ir = 4 × K_rgb (same resolution), so adjacent IR
pixels round to the same RGB pixel."""
W = H = 16
K_rgb = np.array([[60.0, 0.0, W / 2.0],
[0.0, 60.0, H / 2.0],
[0.0, 0.0, 1.0]], dtype=np.float64)
K_ir = K_rgb.copy()
K_ir[0, 0] *= 2.0 # double focal length → two IR pixels collapse to one RGB pixel
K_ir[1, 1] *= 2.0
K_ir[0, 0] *= 4.0 # 4× focal length → adjacent IR pixels collapse to one RGB pixel
K_ir[1, 1] *= 4.0
reg = CameraRegistration(
K_rgb=K_rgb, K_ir=K_ir,
R_ir_to_rgb=np.eye(3, dtype=np.float64),
@@ -73,16 +73,13 @@ def test_z_buffer_keeps_closer_point():
rgb_width=W, rgb_height=H, ir_width=W, ir_height=H,
)
depth_ir = np.zeros((H, W), dtype=np.uint16)
# Two IR pixels (5, 5) and (6, 5) both project to the same RGB pixel near (4, 5)
# (when projected through K_ir with depth 1m and re-projected through K_rgb).
depth_ir[5, 5] = 1500
depth_ir[5, 6] = 800
# IR pixels (8, 8) and (8, 9) both project to RGB pixel (8, 8):
# u_rgb = 0.25*(u_ir - 8) + 8 → 8.0 and 8.25 (both round to 8).
depth_ir[8, 8] = 1500
depth_ir[8, 9] = 800
depth_rgb = align_depth_to_rgb(depth_ir, reg)
nonzero = depth_rgb[depth_rgb > 0]
# At least one RGB pixel must receive the closer (800) value; nothing further
# may be ≥ 1500 if a collision actually occurred. If they didn't collide, we
# see exactly two values [800, 1500]; if they did, we see only [800].
assert nonzero.size in (1, 2)
assert int(nonzero.min()) == 800
if nonzero.size == 1:
assert int(nonzero[0]) == 800 # collision happened, closer point won
# Exactly one filled pixel; z-buffer kept the closer (800) value.
assert nonzero.size == 1
assert int(nonzero[0]) == 800
assert int(depth_rgb[8, 8]) == 800