Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Adaptive Scale Detection

Adaptive scale detection handles images where marker diameters vary widely (for example near/far perspective or mixed focal lengths).

Why Use It

A single marker-size prior can under-detect:

  • very small markers (proposal/search window too large or weak)
  • very large markers (proposal/search window too small)

Adaptive mode runs multiple scale tiers and merges results with size-aware dedup.

API Entry Points

#![allow(unused)]
fn main() {
use ringgrid::{TargetLayout, Detector, ScaleTiers};
use std::path::Path;

let target = TargetLayout::from_json_file(Path::new("target.json"))?;
let detector = Detector::new(target);
let image = image::open("photo.png")?.to_luma8();

// 1) Automatic probe + auto-tier selection (0.8: detect* return Result<_, DetectError>)
let r1 = detector.detect_adaptive(&image).unwrap();

// 2) Optional nominal size hint (px) -> 2-tier bracket around hint
let r2 = detector.detect_adaptive_with_hint(&image, Some(32.0)).unwrap();

// 3) Explicit manual tiers
let tiers = ScaleTiers::four_tier_wide();
let r3 = detector.detect_multiscale(&image, &tiers).unwrap();
let _ = (r1, r2, r3);
Ok::<(), Box<dyn std::error::Error>>(())
}

Tier Presets

PresetTiersDiameter rangeTypical use
ScaleTiers::four_tier_wide()48–220 pxUnknown or extreme scale variation
ScaleTiers::two_tier_standard()214–100 pxModerate variation, lower runtime
ScaleTiers::single(prior)1customSingle-pass equivalent

How detect_adaptive Chooses Tiers

detect_adaptive runs several tier candidates over the image and keeps the best one:

  1. Candidates: tiers from a lightweight scale probe of the code band (coded targets, or any target with a diameter hint — plain rings have no code band), two_tier_standard, four_tier_wide, the configured prior, and a few curated single priors.
  2. Each candidate is one multi-scale detection: one full detect pass per tier, markers merged with size-consistency-aware dedup, then grid labeling, anchoring, completion, final homography refit and geometric verification once on the merged pool.
  3. Candidates are ranked on what the output contract would report: markers with a board position first, then homography support, decoded markers and residual tie-breakers.
  4. The best candidate is joined with the markers other candidates labeled at cells it lacks, from every candidate in the same board placement (absolute board frame, its labeled centres within 2 px of the best candidate’s homography by median); the union’s homography is refit and verified again. Each candidate’s tiers fit a different subset of the rings, so on large oblique views the union reports rings no single candidate does. A cell whose kept marker the output contract would drop (no corrected centre, below min_confidence) takes another candidate’s marker there when that one would be reported: a defocused ring’s inner fit can succeed in one candidate and fail in another.
  5. Photometric refinement, when requested, runs once on the joined result.

When To Prefer Each Method

  • detect():
    • fastest and simplest
    • best when marker size range is relatively tight
  • detect_adaptive():
    • good default when scale is unknown
    • robust across mixed near/far markers
  • detect_adaptive_with_hint(..., Some(d)):
    • use when you have an approximate diameter
    • skips probe and narrows search to a focused two-tier bracket
  • detect_multiscale(...):
    • use when you need explicit control over tiers
    • useful for reproducible experiments and benchmarks

CLI Status

Adaptive entry points are currently Rust API methods. The CLI ringgrid detect uses the regular config-driven detection flow (detect / detect_with_mapper).

Source

  • crates/ringgrid/src/api.rs
  • crates/ringgrid/src/pipeline/run.rs
  • crates/ringgrid/src/detector/config.rs