Skip to main content

chess_corners/config/
multiscale.rs

1use serde::{Deserialize, Serialize};
2
3/// Coarse-to-fine multiscale configuration.
4///
5/// JSON shape mirrors [`crate::UpscaleConfig`]:
6///
7/// - `{ "single_scale": null }` — run the detector once on the full image.
8/// - `{ "pyramid": { "levels": 3, "min_size": 128, "refinement_radius": 3 } }`
9///   — build an image pyramid, detect seeds on the coarsest level, and
10///   refine each seed into the base image. Honoured by both ChESS and
11///   Radon strategies.
12#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
13#[serde(rename_all = "snake_case")]
14#[non_exhaustive]
15pub enum MultiscaleConfig {
16    /// Single-scale detection (no pyramid).
17    #[default]
18    SingleScale,
19    /// Coarse-to-fine pyramid detection.
20    Pyramid {
21        /// Number of pyramid levels (≥ 1). Level 0 is the base image;
22        /// each subsequent level is a 2× box-filter downsample.
23        levels: u8,
24        /// Minimum short-edge length in pixels. The pyramid stops once
25        /// the next level would fall below this size.
26        min_size: usize,
27        /// ROI half-radius at the coarse level used to refine each seed
28        /// into the base image, in coarse-level pixels.
29        refinement_radius: u32,
30    },
31}
32
33impl MultiscaleConfig {
34    /// Three-level pyramid with library defaults (`min_size = 128`, `refinement_radius = 3`).
35    /// Equivalent to the multiscale preset used by [`crate::DetectorConfig::chess_multiscale`]
36    /// and [`crate::DetectorConfig::radon_multiscale`].
37    pub const fn pyramid_default() -> Self {
38        Self::Pyramid {
39            levels: 3,
40            min_size: 128,
41            refinement_radius: 3,
42        }
43    }
44    /// Pyramid with caller-supplied parameters.
45    pub const fn pyramid(levels: u8, min_size: usize, refinement_radius: u32) -> Self {
46        Self::Pyramid {
47            levels,
48            min_size,
49            refinement_radius,
50        }
51    }
52}