corrmatch
CorrMatch is a CPU-first template matching library for grayscale images. It implements a coarse-to-fine pyramid search with optional rotation and two metrics: ZNCC and SSD. The focus is deterministic, reproducible matching with minimal dependencies.
Install
[]
= "0.1"
Quickstart (library)
use ;
# #
Match results (match_image vs match_image_topk)
Matcher::match_image(image)returns the single bestMatch.Matcher::match_image_topk(image, k)returns up tokmatches sorted best-first byscore.
Match fields:
x,y: top-left placement coordinates in the original image (level 0). These aref32because the final refinement can be subpixel.angle_deg: rotation angle in degrees (clockwise, with image coordinates x→ right, y↓ down). When rotation is disabled this is0.0.score: ZNCC is roughly[-1, 1](higher is better). SSD is reported as negative SSE (higher is better).
To retrieve multiple results:
# use ;
# #
If you do not need rotation support, compile a lighter template:
# use ;
#
CLI (corrmatch-cli)
The workspace includes a JSON-driven CLI.
- Build:
cargo build -p corrmatch-cli - Run:
cargo run -p corrmatch-cli -- --config config.json - Print schema:
cargo run -p corrmatch-cli -- --print-schema - Print example:
cargo run -p corrmatch-cli -- --print-example
The schema lives at corrmatch-cli/config.schema.json, and an example config is
at corrmatch-cli/config.example.json.
Concepts
Template: owned template pixels (contiguous grayscale).CompiledTemplate: precomputed template pyramid plus optional angle banks.Matcher: runs coarse-to-fine search usingMatchConfig.Metric:ZnccorSsd.RotationMode:Disabled(fast path) orEnabled(masked rotation search).- Coordinates: results are top-left placement coordinates at level 0.
Configuration
CompileConfigcontrols template pyramid depth and rotation grid. When rotation is disabled, onlymax_levelsis used.MatchConfigcontrols the search strategy (beam width, ROI size, NMS radius, and angle neighborhood). For SSD,min_var_iis ignored.
Feature flags
rayon: parallel search execution.simd: SIMD-accelerated kernels (currently: unmasked translation-only path).image-io: file I/O helpers via theimagecrate.
Python bindings (corrmatch-py)
The workspace includes PyO3 bindings in corrmatch-py.
- Build locally:
cd corrmatch-py && maturin develop --release - Run tests:
python -m pytest python/tests
Python API notes:
Matcher.match_image(image)returns acorrmatch.Matchwith fieldsx,y,angle_deg,score.Matcher.match_topk(image, k)returns a Pythonlist[corrmatch.Match]sorted best-first byscore.- Angle convention matches Rust: positive angles are clockwise.
Example (match + visualize):
=
=
=
=
=
=
=
=
= # sorted best-first
Low-level API
Advanced hooks live in corrmatch::lowlevel, including template plans, kernel
traits, scan helpers, and rotation utilities. These are intended for custom
pipelines and experimentation.
Image I/O (feature image-io)
#
#
Benchmarks and tests
cargo testcargo test --features rayoncargo bench
Validation and performance tracking
- Synthetic validation suite (ground truth cases):
docs/VALIDATION.md - Criterion benchmarks and latest numbers:
performance.md - Release checklist (crates.io + PyPI):
docs/RELEASE_CHECKLIST.md
Synthetic case examples
This repo includes ground-truth synthetic cases in synthetic_cases/.
Note: the per-case cli_config.json uses relative paths like image.png, so run
the CLI from inside the case directory (or use the Python helper below).
Quick visual impressions (templates + saved overlays in book/images/):
| Case | Template | Detection overlay |
|---|---|---|
blur_sigma_1_5 |
||
rotation_fine_22_5deg |
||
distractors_topk |
blur_sigma_1_5 (translation-only, blurred)
- CLI:
(cd synthetic_cases/blur_sigma_1_5 && cargo run --manifest-path ../../Cargo.toml -p corrmatch-cli -- --config cli_config.json)
- Visualize (requires
corrmatch-pyinstalled):./tools/viz_case.sh blur_sigma_1_5 1
rotation_fine_22_5deg (rotation enabled)
- CLI:
(cd synthetic_cases/rotation_fine_22_5deg && cargo run --manifest-path ../../Cargo.toml -p corrmatch-cli -- --config cli_config.json)
- Visualize:
./tools/viz_case.sh rotation_fine_22_5deg 1
distractors_topk (multiple candidates)
- CLI:
(cd synthetic_cases/distractors_topk && cargo run --manifest-path ../../Cargo.toml -p corrmatch-cli -- --config cli_config.json)
- Visualize top-4 overlays:
./tools/viz_case.sh distractors_topk 4
Status
Core matcher types, the JSON-driven CLI, and Python bindings are implemented.
See ROADMAP.md for upcoming milestones.