Skip to main content

Module validate

Module validate 

Source
Expand description

Post-growth validation for a labelled square grid.

Two independent checks run over the labelled set by default:

  1. Line collinearity. For every row (j = const) and column (i = const) with ≥ line_min_members labelled members, fit a least-squares line in pixel space and flag any member whose perpendicular residual exceeds line_tol_rel × scale.

  2. Local-H residual. For every labelled corner with ≥ 4 non-collinear labelled neighbors in (i, j)-space, fit a 4-point local homography from the 4 grid-closest neighbors, predict the corner’s pixel position, and measure the residual. Corners whose residual exceeds local_h_tol_rel × scale are flagged.

scale is either the caller-supplied global cell_size (default mode) or — when ValidationParams::use_step_aware is set — a per-corner local step computed from labelled grid neighbours via central or one-sided finite differences. Per-corner thresholds are anisotropic: cells in perspective-foreshortened regions get a tighter pixel tolerance proportional to their (smaller) local step; cells in radially-distorted regions get a looser one. Corners without enough labelled neighbours fall back to the global cell_size.

Flags are combined via the attribution rules below into a blacklist of indices into the input slice:

  • A corner flagged in ≥ 2 lines is the outlier.
  • A corner with a large local-H residual (> 2 × local_h_tol) AND at least one line flag is the outlier.
  • A corner with a local-H flag but NO line flag, where at least one of its 4 base neighbors has ≥ 1 line flags, blames the worst- line-flagged base instead (the base is the outlier).
  • When ValidationParams::step_deviation_thresh_rel is set, a corner whose local step deviates from the labelled-set median by more than the threshold AND has ≥ 1 line flag is also an outlier.
  • Otherwise (isolated local-H flag with no supporting evidence), defer — no blacklist entry in this iteration.

The caller is expected to re-run the topological recovery/validate loop after updating its blacklist.

An optional edge-shape gate is available for final validation of a completed labelled grid. It rejects labels with too little cardinal support, bad adjacent-edge continuation, or no valid adjacent square cell under local opposite-side consistency. This gate is opt-in so the historical grow-time validator remains conservative.

§Pattern-agnostic

This module has no dependency on target-specific vocabulary such as feature-class labels or target IDs. Any caller that can produce a (corner_index, pixel_position, grid_coord) slice can use it. Consumers that carry per-stage metadata should pre-filter to the “labelled” subset before calling.

Modules§

wrong_label_filters
Lattice-general final-recovery filters used by a detector’s mandatory geometry check.

Structs§

EdgeShapeDiagnostic
Per-label diagnostics from local edge-shape validation.
EdgeShapeParams
Tolerances for local square-grid edge-shape validation.
LabelledEntry
A single labelled corner fed into validate: its caller-chosen index (carried back in ValidationResult::blacklist), its pixel position, and its integer grid coordinate.
ValidationParams
Tolerances for the validation pass.
ValidationResult
Outcome of one validation pass.

Functions§

validate
Run both validation passes and produce a blacklist.