code wiki / _hdl_build / nx_image_fidelity.nx

nx_image_fidelity.nx

buildroot/runtime/_hdl_build/nx_image_fidelity.nx

2689 B54 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind librarytopic image
docsdependenciesstructsconstsfunctions

about

SUPERSEDED-FOR-GENERATION (Critic, Blau-Michaeli): this measures DISTORTION only (MSE/PSNR), which is correct for lossless RECONSTRUCTION but MISLEADING for generative quality -- a blurry posterior-mean scores high PSNR yet looks fake. For generation, pair this with the PERCEPTION axis in nx_rd_perception (distribution divergence). Distortion and perception trade off; never judge a generative output by PSNR alone. nx_image_fidelity.nx -- "rebuild it EXACTLY": the measurement gate for image reconstruction, bits-up. You cannot claim a rebuild is exact without measuring exactness; the precision research flagged measurement as the weak link. This is the sovereign metric layer the generation stack (our nx_qmatvec/nx_qlayer kernels -> VAE -> DiT) is judged by: how close is the rebuilt image to the reference? MSE (exact integer), max-abs-error (the worst pixel -- catches local failures an average hides), and PSNR in dB (the rate-distortion quality measure). Verdict: LOSSLESS (bit- exact) / NEAR-LOSSLESS / LOSSY. Pixels are 0..255 per channel, stored one per slot. license_tier: ORIGINAL Refs: PSNR/MSE (rate-distortion fidelity); SSIM lineage.

dependencies 1 imports · 1 importers

nx_syscalls.nx nx_image_fidelity.nx nx_image_fidelity_test.nx

imports: nx_syscalls.nx

imported by: nx_image_fidelity_test.nx

structs

none

consts

17const IMG_MAGIC_65025: i64 = 65025
19const IMG_LOSSLESS: i64 = 0 // bit-exact rebuild (max-err 0)
20const IMG_NEAR: i64 = 1 // PSNR >= 40 dB, imperceptible
21const IMG_LOSSY: i64 = 2 // below the near-lossless bar

functions

24func img_ilog2(v: i64) -> i64 { var x: i64 = v; var n: i64 = 0; while x > 1 { x = x >> 1; n = n + 1 } return n }
called by 1: img_psnr_db
27func img_mse(ref: *i64, got: *i64, n: i64) -> i64
called by 2: img_verdictmain
35func img_max_abs_err(ref: *i64, got: *i64, n: i64) -> i64
called by 2: img_verdictmain
42func img_psnr_db(mse: i64) -> i64
called by 2: img_verdictmain calls 1: img_ilog2
50func img_verdict(ref: *i64, got: *i64, n: i64) -> i64