depth_fm.data.image_processing.seam_detection¶
seam_detection ¶
Seam and TIN-artifact detection for HiRISE DTM patches.
Public entry points:
detect_seam_artifact— main detector. Returns aSeamResult.is_tin_artifact— scale-invariant TIN-flat-region detector.SeamResult— dataclass with score, line geometry, and (optional) diagnostic arrays.
Public helpers (also used by training-time diagnostics):
compute_piecewise_linearity— Hough-based linearity score.compute_artifact_multipliers— span/sparsity structural multipliers.compute_spatial_isolation— perpendicular cross-section isolation score.
Private gradient helpers (_ensure_bchw, _sobel_mag, _sharp_grad_mag,
_build_oriented_kernels) stay inside this module — they are only used by
detect_seam_artifact.
SeamResult
dataclass
¶
SeamResult(seam_score: float, ortho_score: float, dtm_score: float, cohens_d: float, best_angle_rad: float, best_y: int, best_x: int, line_length: int, num_angles: int, span: float, sparsity: float, composite_score: float, is_seam: bool, seam_heatmap: Optional[ndarray] = None, cohens_d_heatmap: Optional[ndarray] = None, per_angle_max: Optional[ndarray] = None, diag_hot_mask: Optional[ndarray] = None, diag_closed_components: Optional[ndarray] = None, diag_hough_lines: Optional[ndarray] = None, diag_isolation_profile: Optional[tuple] = None)
line_endpoints ¶
Return (y1, x1, y2, x2) pixel endpoints of the best-scoring line.
Source code in src/depth_fm/data/image_processing/seam_detection.py
compute_piecewise_linearity ¶
compute_piecewise_linearity(seam_heatmap: ndarray, threshold_ratio: float = 0.3) -> tuple[float, np.ndarray]
Score how piecewise-linear the high-scoring pixels are (handles corners).
Returns (linearity_score, line_mask) where linearity is in [0.0, 1.0]: 1.0 = highly structured/linear, 0.0 = curved/messy.
Source code in src/depth_fm/data/image_processing/seam_detection.py
compute_artifact_multipliers ¶
compute_artifact_multipliers(seam_heatmap: ndarray, valid_mask: ndarray, threshold: float = 0.2) -> tuple[float, float, np.ndarray, np.ndarray]
Compute structural multipliers that distinguish seams from natural features.
Returns (span_ratio, sparsity, hot_mask, labels): * span_ratio — defeats short craters; true seams cross the whole tile. * sparsity — defeats dense dunes; true seams are a singular line.
Source code in src/depth_fm/data/image_processing/seam_detection.py
compute_spatial_isolation ¶
compute_spatial_isolation(score_map: Tensor, valid_mask: Tensor, best_x: int, best_y: int, angle_rad: float, profile_length: int = 50, exclusion_zone: int = 12) -> tuple[float, Optional[tuple]]
Sample a perpendicular slice across the seam.
Returns the ratio of the central peak to the surrounding parallel background, plus the raw profile data arrays for visualization.
Source code in src/depth_fm/data/image_processing/seam_detection.py
detect_seam_artifact ¶
detect_seam_artifact(ortho: Tensor, elevation: Tensor, valid_mask: Tensor, line_length: int = 41, num_angles: int = 12, side_offset: int = 2, min_valid_ratio: float = 0.6, ortho_weight: float = 1.0, dtm_weight: float = 0.3, erosion_kernel: int = 9, seam_threshold: float = 2.4, return_diagnostics: bool = False) -> SeamResult
Detect seam artifacts (mosaicking discontinuities) in a HiRISE patch.
Returns a SeamResult. With return_diagnostics=True, the result also
carries seam_heatmap, cohens_d_heatmap, and per_angle_max, used by
the visualization and refinement UI to show where and along which
angle the detector fired.
Source code in src/depth_fm/data/image_processing/seam_detection.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |
is_tin_artifact ¶
Scale-invariant TIN-artifact detection using localized maximum density.
Returns the maximum local fraction of zero-curvature pixels within any
kernel_size × kernel_size window. Patches with stretched-triangle TIN
artifacts produce values near 1.0; natural terrain produces values <0.5.