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
Owner

Second pixel-domain post-filter — a scale-gated unsharp mask on the luma plane:

n=y/255 ; blur=clamp(conv3x3(n,[[5,5,5],[5,24,5],[5,5,5]]/64),0,1) (valid; border keeps n)
factor=mag[k] gated by region in the thr bands, else 1
out=clamp(blur+(n-blur)*factor,0,1)*255

The 3x3 conv is valid (no padding) — interior blurs, border passes through. region = the scale grid nearest-upsampled to pixel res, gating sharpening strength.

Validated vs the reference fixture: max|Δ| = 1.5e-5 (f32-vs-f64), SNR 153 dB. Plus unit tests (flat-plane invariance, border pass-through, factor>1 sharpen gate).

Second pixel-domain post-filter — a scale-gated unsharp mask on the luma plane: ``` n=y/255 ; blur=clamp(conv3x3(n,[[5,5,5],[5,24,5],[5,5,5]]/64),0,1) (valid; border keeps n) factor=mag[k] gated by region in the thr bands, else 1 out=clamp(blur+(n-blur)*factor,0,1)*255 ``` The 3x3 conv is valid (no padding) — interior blurs, border passes through. `region` = the scale grid nearest-upsampled to pixel res, gating sharpening strength. **Validated vs the reference fixture: max|Δ| = 1.5e-5 (f32-vs-f64), SNR 153 dB.** Plus unit tests (flat-plane invariance, border pass-through, factor>1 sharpen gate).
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]>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Transaction-Science/open-standards!10
No description provided.