Skip to content

modosaic.depth.validators.impl.depth_seg_boundary_consistency_validator

modosaic.depth.validators.impl.depth_seg_boundary_consistency_validator

DepthSegBoundaryConsistencyValidator

DepthSegBoundaryConsistencyValidator(boundary_thickness=1, tolerance_radius=2, depth_edge_quantile=0.9)

Bases: DepthValidator[BoundaryAlignmentStats]

Compare depth-map edges with segmentation-mask boundaries.

Initialize the validator.

Parameters:

Name Type Description Default
boundary_thickness int

Mask boundary thickness in pixels.

1
tolerance_radius int

Pixel tolerance used for precision and recall.

2
depth_edge_quantile float

Quantile threshold for depth edge detection.

0.9
Source code in modosaic/depth/validators/impl/depth_seg_boundary_consistency_validator.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def __init__(
        self,
        boundary_thickness: int = 1,
        tolerance_radius: int = 2,
        depth_edge_quantile: float = 0.90,
) -> None:
    """Initialize the validator.

    Args:
        boundary_thickness: Mask boundary thickness in pixels.
        tolerance_radius: Pixel tolerance used for precision and recall.
        depth_edge_quantile: Quantile threshold for depth edge detection.
    """
    self.boundary_thickness = boundary_thickness
    self.tolerance_radius = tolerance_radius
    self.depth_edge_quantile = depth_edge_quantile

validate

validate(record, generated, masks=None)

Compute boundary alignment between generated depth and masks.

Source code in modosaic/depth/validators/impl/depth_seg_boundary_consistency_validator.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@override
def validate(self, record: ImageRecord, generated: np.ndarray,
             masks: list[np.ndarray] | None = None) -> BoundaryAlignmentStats:
    """Compute boundary alignment between generated depth and masks."""
    if not masks:
        return BoundaryAlignmentStats()

    depth, valid_mask = BoundaryService.coerce_hw_float_with_mask(generated)
    if not np.any(valid_mask):
        return BoundaryAlignmentStats()

    logger.debug(
        f"Computing boundary alignment stats for record sample {record.sample_id} with depth shape {depth.shape} and "
        f"{len(masks)} segmentation masks")
    boundary = BoundaryService.masks_to_boundary(masks, expected_shape=depth.shape,
                                                 thickness=self.boundary_thickness)

    if not np.any(boundary):
        return BoundaryAlignmentStats()

    depth_edges = EdgeService.sobel_edge_map_float(
        depth,
        blur_ksize=3,
        q=self.depth_edge_quantile,
        valid_mask=valid_mask,
    )

    stats = ToleranceService.compute_boundary_alignment_stats(
        edge_map=depth_edges,
        boundary_map=boundary,
        tolerance_radius=self.tolerance_radius,
    )
    logger.debug(f"Computed boundary alignment stats for record sample {record.sample_id}")
    return stats