chess_corners/config/radon.rs
1use chess_corners_core::{PeakFitMode, RadonDetectorParams};
2use serde::{Deserialize, Serialize};
3
4/// Configuration for the whole-image Radon detector branch of
5/// [`crate::DetectionStrategy`].
6///
7/// All radii and counts are in **working-resolution** pixels (i.e.
8/// after `image_upsample`). The shared NMS / clustering thresholds
9/// ([`crate::DetectionParams`]), multiscale, and upscale live at the top level
10/// of [`crate::DetectorConfig`] and apply to both strategies.
11///
12/// # Common knobs
13///
14/// - [`image_upsample`](RadonConfig::image_upsample) — `2` (the default)
15/// reproduces the paper's 2× supersampled detection; `1` is faster but
16/// less accurate on low-resolution inputs.
17///
18/// # Advanced tuning
19///
20/// The remaining fields control low-level detection behaviour. The
21/// defaults reproduce the paper's recommended settings and work well
22/// for typical camera images. Adjust them only when you have a specific
23/// reason (e.g. a non-standard image resolution or SNR budget).
24#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
25#[serde(default)]
26#[non_exhaustive]
27pub struct RadonConfig {
28 /// Advanced tuning. Half-length of each Radon ray in
29 /// working-resolution pixels. The ray has `2·ray_radius + 1`
30 /// samples. Paper default at `image_upsample = 2` is `ray_radius = 4`.
31 /// Shorter rays are faster but integrate less signal; longer rays are
32 /// more discriminating but may cross into neighbouring cells.
33 pub ray_radius: u32,
34 /// Image-level supersampling factor applied before ray integration.
35 /// `1` operates on the input grid; `2` (paper default) is equivalent
36 /// to bilinearly upsampling the input first, giving sub-pixel ray
37 /// positioning. Values ≥ 3 are clamped to 2 by the core detector.
38 pub image_upsample: u32,
39 /// Advanced tuning. Half-size of the box blur applied to the Radon
40 /// response map after integration. `0` disables blurring; `1`
41 /// (default) yields a 3×3 box, smoothing quantisation noise in the
42 /// response. Increase only on very high-SNR images where extra
43 /// smoothing is unwanted.
44 pub response_blur_radius: u32,
45 /// Advanced tuning. Peak-fit mode for the 3-point subpixel
46 /// refinement of the response-map argmax. `Gaussian` (default) fits
47 /// on log-response (more accurate near the peak); `Parabolic` fits
48 /// directly on the response values. See [`PeakFitMode`].
49 pub peak_fit: PeakFitMode,
50}
51
52impl Default for RadonConfig {
53 fn default() -> Self {
54 // Single source of truth: mirror `RadonDetectorParams::default()`
55 // (chess-corners-core) rather than restating the paper defaults here.
56 let core_defaults = RadonDetectorParams::default();
57 Self {
58 ray_radius: core_defaults.ray_radius,
59 image_upsample: core_defaults.image_upsample,
60 response_blur_radius: core_defaults.response_blur_radius,
61 peak_fit: core_defaults.peak_fit,
62 }
63 }
64}