code wiki / (root) / nx_natstat.nx

nx_natstat.nx

buildroot/runtime/nx_natstat.nx

19396 B471 linesdepth 2pulls 2 transitivereach 9 importersview sourcekind librarytopic natstat
docsdependenciesstructsconstsfunctions

about

nx_natstat.nx -- NATURAL-IMAGE-STATISTICS photoreal metric = the REVERSE AI JUDGE. Real photographs have a signature our old critic missed: DETAIL AT EVERY SCALE (a ~1/f amplitude spectrum -> roughly EQUAL detail energy per octave). Clay/CG fails it two ways: too SMOOTH (fine + mid octaves empty) or GRAIN-ONLY (a spike at the finest octave, smooth beneath). We measure the multi-scale detail profile + its balance (+ gradient heavy-tail + colour spread) and return a graded PHOTOREAL LEVEL 0..1000. Uses: (a) REVERSE JUDGE: maximise this to push Z-Image toward more-real output for games/VR (evaluator-in-reverse); (b) "USE-AS-PHOTOREAL-TO-LEVEL": even a known-AI image is usable as photoreal up to the level it scores. Integer, deterministic, no FFT (Laplacian-pyramid octave energies). license_tier: ORIGINAL

dependencies 1 imports · 9 importers

nx_syscalls.nx nx_natstat.nx nx_engine_scene_gate.nx nx_face_project_gate.nx nx_face_vs_target.nx nx_grade.nx nx_natstat_corpus.nx nx_natstat_hardcases.nx nx_natstat_optimize.nx nx_natstat_redteam_gate.nx nx_render_judge_gate.nx

imports: nx_syscalls.nx

imported by: nx_engine_scene_gate.nxnx_face_project_gate.nxnx_face_vs_target.nxnx_grade.nxnx_natstat_corpus.nxnx_natstat_hardcases.nxnx_natstat_optimize.nxnx_natstat_redteam_gate.nxnx_render_judge_gate.nx

structs

none

consts

10const K_MAGIC_65536: i64 = 65536
11const K_MAGIC_3200: i64 = 3200
12const K_MAGIC_6500: i64 = 6500

functions

14func ns_lum(g: i64) -> i64 { return ((g & 255) + ((g >> 8) & 255) + ((g >> 16) & 255)) / 3 }
15func ns_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
16func ns_isqrt(v: i64) -> i64 { if v <= 0 { return 0 } var x: i64 = v; var y: i64 = (x + 1) / 2; while y < x { x = y; y = (x + v / x) / 2 } return x }
21func ns_mscn_rho(fb: *i64, w: i64, h: i64) -> i64
62func ns_mscn_fill(fb: *i64, w: i64, h: i64, mbuf: *i64) -> i64
called by 1: ns_assess calls 2: ns_lumns_isqrt
93func ns_mscn_rho_buf(mbuf: *i64, w: i64, h: i64) -> i64
called by 1: ns_assess calls 1: ns_abs
115func ns_mscn_pair(mbuf: *i64, w: i64, h: i64, dx: i64, dy: i64) -> i64
called by 1: ns_assess
133func ns_detail(fb: *i64, w: i64, h: i64) -> i64
154func ns_local_std(fb: *i64, w: i64, x: i64, y: i64) -> i64
called by 1: ns_grad_kurt calls 2: ns_lumns_isqrt
176func ns_grad_kurt(fb: *i64, w: i64, h: i64) -> i64
217func ns_colorful(fb: *i64, w: i64, h: i64) -> i64
called by 2: ns_assessmain calls 1: ns_isqrt
253func ns_ai_periodicity(fb: *i64, w: i64, h: i64) -> i64
called by 2: ns_assessmain calls 2: ns_lumns_abs
275func ns_down2(fb: *i64, w: i64, h: i64, out: *i64) -> i64
297func ns_scale_spread(fb: *i64, w: i64, h: i64, buf1: *i64, buf2: *i64) -> i64
320func ns_band(v: i64, lo: i64, hi: i64, edge: i64) -> i64
called by 2: ns_assessmain
334func ns_assess(fb: *i64, w: i64, h: i64, buf1: *i64, buf2: *i64, out: *i64) -> i64
411func ns_photoreal(fb: *i64, w: i64, h: i64, buf1: *i64, buf2: *i64) -> i64
419func ns_coherence(fb: *i64, w: i64, h: i64) -> i64
called by 2: ns_assess2main calls 1: ns_lum
451func ns_assess2(fb: *i64, w: i64, h: i64, buf1: *i64, buf2: *i64, out: *i64) -> i64
called by 2: g_runmain calls 2: ns_assessns_coherence
459func ns_verdict(level: i64) -> *u8
called by 2: maing_run
465func ns_axisname(i: i64) -> *u8
called by 1: main