wai-rs: jpegai_pipeline::lef_filter — LEF adaptive-sharpness post-filter #10

Merged
dcharlot merged 1 commit from feat/jpegai-lef into main 2026-07-14 05:19:47 -04:00

2026-07-14

Transaction Science
wai-rs: jpegai_pipeline::lef_filter — LEF adaptive-sharpness post-filter (float-exact)
Second pixel-domain post-filter — a scale-gated unsharp mask on the luma plane:

  n      = y_in / 255
  blur   = clamp( conv3x3(n, [[5,5,5],[5,24,5],[5,5,5]]/64), 0, 1 )   // valid; border keeps n
  factor = mag[k] where region in [thr[k], thr[k+1]) (k=0,1) or region >= thr[2]; else 1
  out    = clamp( blur + (n - blur)*factor, 0, 1 ) * 255

The 3x3 conv is "valid" (no padding) — interior pixels blur, the 1-pixel border passes
through — matching the reference's pad-and-mask trick. `region` gates the sharpening
strength: the scale grid (sigma, 16x16) nearest-upsampled to pixel resolution.

Validated against the reference fixture (input luma + 16x16 scale + thr/mag → sharpened
luma): max|Δ| = 1.5e-5 (f32-vs-f64), SNR 153 dB. Plus unit tests for the flat-plane
invariance, the border pass-through, and the factor>1 sharpening gate.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-14 05:13:39 -04:00