feat: unify reference depth calculation by using median-based range factor and baseline

This commit is contained in:
2026-09-16 01:04:59 +08:00
parent 474fc10f0f
commit cf512dc013
6 changed files with 45 additions and 36 deletions

View File

@@ -11,7 +11,8 @@ from .image import depth_data_name, image_empty_bounds
PLANE_VARIANCE_FLOOR_RATIO = 0.025
REFERENCE_DEPTH_PERCENTILE = 95.0
DEPTH_ALPHA_THRESHOLD = 0.95
REFERENCE_DEPTH_LIMIT = 8.0
REFERENCE_DEPTH_RANGE_FACTOR = 1.1
REFERENCE_DEPTH_BASELINE = 8.0
FLAT_DEPTH_DIRECTION = (0.0, 1.0, 0.0)
@@ -72,10 +73,10 @@ def reference_depth(image, mask=None):
"""Return the upper-percentile camera depth of a loaded Depth texture.
Distances are in model meters. Samples farther than
``REFERENCE_DEPTH_LIMIT`` are dropped so a distant background cannot push
the reference plane, and with it the whole reconstruction scale, out to
the far field. The limit itself is the reference when the selection leaves
no sample.
``REFERENCE_DEPTH_RANGE_FACTOR`` times the median are dropped so a distant
background cannot push the reference plane, and with it the whole
reconstruction scale, out to the far field. A selection without usable
samples returns ``REFERENCE_DEPTH_BASELINE``.
"""
import numpy as np
@@ -87,10 +88,12 @@ def reference_depth(image, mask=None):
raise ValueError("Depth reference mask dimensions do not match")
usable &= mask
values = depth[usable]
values = values[values <= REFERENCE_DEPTH_LIMIT]
if not values.size:
return REFERENCE_DEPTH_LIMIT
return float(np.percentile(values, REFERENCE_DEPTH_PERCENTILE))
return REFERENCE_DEPTH_BASELINE
near = values[
values <= REFERENCE_DEPTH_RANGE_FACTOR * float(np.median(values))
]
return float(np.percentile(near, REFERENCE_DEPTH_PERCENTILE))
def _weighted_depth_plane(coordinates, values, weights):