junaid-simamdigital commited on
Commit
e30fe54
·
verified ·
1 Parent(s): fce804f

Add relative-depth reprojection consistency metrics

Browse files
Files changed (1) hide show
  1. simam3d_core.py +34 -0
simam3d_core.py CHANGED
@@ -335,6 +335,40 @@ def project_world_points(
335
  return pixels, camera[:, 2].astype(np.float32), inside
336
 
337
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
  def depth_to_camera_points(
339
  depth: np.ndarray,
340
  intrinsics: np.ndarray | None = None,
 
335
  return pixels, camera[:, 2].astype(np.float32), inside
336
 
337
 
338
+ def reprojection_consistency(
339
+ points: np.ndarray,
340
+ depth: np.ndarray,
341
+ intrinsics: np.ndarray | None,
342
+ extrinsics: np.ndarray | None,
343
+ ) -> dict[str, float]:
344
+ """Compare fused-point depth against a view's relative depth prediction."""
345
+ depth = np.asarray(depth, dtype=np.float32)
346
+ if depth.ndim != 2:
347
+ raise ValueError("depth must be a 2-D map")
348
+ height, width = depth.shape
349
+ pixels, point_depth, inside = project_world_points(
350
+ points, intrinsics, extrinsics, width, height
351
+ )
352
+ if not inside.any():
353
+ return {"coverage": 0.0, "mean_absolute_error": 0.0, "median_absolute_error": 0.0}
354
+ raster = np.full((height, width), np.nan, dtype=np.float32)
355
+ pixel_x = np.clip(np.rint(pixels[inside, 0]).astype(np.int64), 0, width - 1)
356
+ pixel_y = np.clip(np.rint(pixels[inside, 1]).astype(np.int64), 0, height - 1)
357
+ for x, y, value in zip(pixel_x, pixel_y, point_depth[inside]):
358
+ if not np.isfinite(raster[y, x]) or value < raster[y, x]:
359
+ raster[y, x] = value
360
+ valid = np.isfinite(raster)
361
+ if not valid.any():
362
+ return {"coverage": 0.0, "mean_absolute_error": 0.0, "median_absolute_error": 0.0}
363
+ target = 1.0 - normalize_map(depth)
364
+ error = np.abs(raster[valid] - target[valid])
365
+ return {
366
+ "coverage": float(valid.mean()),
367
+ "mean_absolute_error": float(error.mean()),
368
+ "median_absolute_error": float(np.median(error)),
369
+ }
370
+
371
+
372
  def depth_to_camera_points(
373
  depth: np.ndarray,
374
  intrinsics: np.ndarray | None = None,