Third pixel-domain post-filter — a per-plane linear cross-component (luma-into-chroma) combine: out = w_uv·(x - mean) + w_y·y + mean `w_uv` is the chroma self-gain about its plane mean, `w_y` the luma cross-gain, `mean` the chroma plane mean. The luma plane is left unchanged. (The reference's multi-tap per-plane linear model reduces, for the reconstructed image, to this 1-tap form — verified against the fixture.) Validated against the reference fixture, both chroma planes: max|Δ| = 1.5e-5 (f32-vs-f64). Plus unit tests for the cross-component combine and the w_uv=0 collapse. Co-Authored-By: Claude Opus 4.8 <[email protected]>
33 lines
1.7 KiB
Rust
33 lines
1.7 KiB
Rust
//! Calibration for [`wai::jpegai_pipeline::efl_chroma`] — the EFE linear per-plane
|
|
//! cross-component filter. Runs on the reference fixture (luma + each chroma plane with
|
|
//! its `w_uv`/`w_y`/`mean`) and compares against the reference filtered plane. Float
|
|
//! arithmetic ⇒ machine-precision match expected.
|
|
//!
|
|
//! env: WAI_JPEGAI_EFL_FIXTURE = efl_fixture.json
|
|
//! { y:[f64], planes:[ { x:[f64], want:[f64], w_uv, w_y, mean } ] }
|
|
#![cfg(feature = "neural_int")]
|
|
|
|
use wai::jpegai_pipeline::efl_chroma;
|
|
|
|
#[test]
|
|
fn efl_chroma_matches_reference() {
|
|
let path = match std::env::var("WAI_JPEGAI_EFL_FIXTURE") {
|
|
Ok(p) if std::path::Path::new(&p).exists() => p,
|
|
_ => { eprintln!("skip: set WAI_JPEGAI_EFL_FIXTURE to efl_fixture.json"); return; }
|
|
};
|
|
let v: serde_json::Value = serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();
|
|
let f32arr = |a: &serde_json::Value| a.as_array().unwrap().iter().map(|x| x.as_f64().unwrap() as f32).collect::<Vec<f32>>();
|
|
let y = f32arr(&v["y"]);
|
|
|
|
for (pi, p) in v["planes"].as_array().unwrap().iter().enumerate() {
|
|
let x = f32arr(&p["x"]);
|
|
let want = f32arr(&p["want"]);
|
|
let (w_uv, w_y, mean) = (p["w_uv"].as_f64().unwrap() as f32, p["w_y"].as_f64().unwrap() as f32, p["mean"].as_f64().unwrap() as f32);
|
|
let got = efl_chroma(&x, &y, w_uv, w_y, mean);
|
|
assert_eq!(got.len(), want.len(), "plane {pi}: size mismatch");
|
|
let mut maxd = 0f32;
|
|
for i in 0..got.len() { maxd = maxd.max((got[i] - want[i]).abs()); }
|
|
eprintln!("efl_chroma plane {pi} vs reference: max|Δ| = {maxd:.6}");
|
|
assert!(maxd < 1e-2, "plane {pi}: EFL diverged (max|Δ| = {maxd})");
|
|
}
|
|
}
|