resamplescope-rs
Reverse-engineer the resampling filter used by any image resizer.
Port of ResampleScope by Jason Summers (~1400 lines of C) to Rust. The original tool generates test images with known pixel patterns, has the resizer process them, then reconstructs the filter kernel shape from the output.
This port replaces that file-based workflow with a callback API: you provide a resize closure, the crate handles everything in-memory. It adds scoring against reference filters, SSIM comparison, and edge handling detection.
How it works
- Generates test patterns (a dot grid for downscale, a single bright column for upscale)
- Passes them through your resize function
- Reconstructs the filter kernel from the output pixel values
- Scores the result against known filters (Box, Triangle, Hermite, Mitchell, Lanczos, etc.)
- Returns the best match with correlation, RMS error, and detected support radius
Usage
use ;
use ;
// Wrap your resizer to accept grayscale u8 images.
let config = AnalysisConfig ;
let result = analyze.unwrap;
if let Some = result.best_match
// Render a 600x300 scope graph as ImgVec<RGB8>.
let graph = result.render_graph;
// Or with a reference filter overlay:
let graph = result.render_graph_with_reference;
What you get back
AnalysisResult contains:
downscale_curve-- reconstructed filter from the dot pattern (557->555 downscale)upscale_curve-- reconstructed filter from the line pattern (15->555 upscale)scores-- sorted best-first by Pearson correlation against known filtersedge_mode-- detected edge handling (Clamp, Reflect, Wrap, Zero, or Unknown)
Each FilterScore includes correlation, RMS error, max error, and detected vs. expected support radius.
Known filters
Box, Triangle, Hermite, Catmull-Rom, Mitchell, B-Spline, Lanczos2, Lanczos3, Lanczos4, and arbitrary Mitchell-Netravali(B, C) parameterization.
Reference resize
The reference module provides perfect_resize and compute_weights for generating
mathematically exact resize output for any built-in filter. Useful for SSIM comparison
against your resizer's output.
No I/O
This crate has no image codec dependencies. It works with ImgVec<u8> (grayscale)
and ImgVec<RGB8> (graph output). You handle your own PNG/JPEG encoding.
Original work
- Author: Jason Summers
- Website: http://entropymine.com/resamplescope/
- License of original: GPL-3.0-or-later
The test pattern generation and filter reconstruction algorithms are ported from the original C source.
The reference filter math uses standard mathematical definitions (sinc, Mitchell-Netravali, etc.). The authoritative, optimized implementations of these filters live in imageflow.
License
AGPL-3.0-or-later.