code wiki / (root) / nx_lbp_img.nx

nx_lbp_img.nx source

↩ module page · 42 lines · 2339 B

1// nx_lbp_img.nx -- SOVEREIGN face-descriptor RUNG 2 GATE: bridge the LBP descriptor to REAL pixels. 2// Reads real gallery PNGs (nx_png_decoder, RFC2083), luma-grayscales them (nx_lbp_core.rgb_to_gray), 3// and runs the LBP histogram. Proves: decode ok + histogram covers exactly the interior pixels + 4// self-distance is 0 + two distinct images give distinct descriptors (chi2>0). Discrimination of 5// SAME-person vs DIFFERENT-person (measured against the insightface benchmark) is a later rung. 6// Build/run: ./_offc/nx_sov_build_run.elf nx_lbp_img license_tier: ORIGINAL 7import "nx_syscalls.nx" 8import "nx_lbp_core.nx" 9import "nx_lbp_imgio.nx" 10 11func descr(path: *u8, tag: *u8, hist: *i64) -> i64 { 12 let wp: *i64 = sys_mmap(8) as *i64; let hp: *i64 = sys_mmap(8) as *i64 13 let g: *u8 = load_gray(path, wp, hp) 14 if (g as i64) == 0 { lp(tag); lp(" DECODE-FAIL\n" as *u8); return 0 - 1 } 15 let w: i64 = wp[0]; let h: i64 = hp[0] 16 zero256(hist); lbp_hist(g, w, h, hist) 17 let interior: i64 = (w-2)*(h-2) 18 lp(tag); lp(" "); ln(w); lp("x"); ln(h); lp(" hist_sum="); ln(hsum(hist)); lp(" interior="); ln(interior) 19 if hsum(hist) == interior { lp(" [sum==interior OK]\n" as *u8); return 0 } 20 lp(" [sum!=interior FAIL]\n" as *u8); return 0 - 2 21} 22 23func main() -> i64 { 24 var fail: i64 = 0 25 let pA: *u8 = "/mnt/c/Users/elder/elder-ai-platform/data-vault/images/2026-06-14/20260614_000018_310470d0_3787058372_laptop.png" as *u8 26 let pB: *u8 = "/mnt/c/Users/elder/elder-ai-platform/data-vault/images/2026-06-14/20260614_000036_cfd6442e_2031691026_laptop.png" as *u8 27 28 let hA: *i64 = sys_mmap(8*256) as *i64 29 let hB: *i64 = sys_mmap(8*256) as *i64 30 if descr(pA, "imgA" as *u8, hA) != 0 { fail = 1 } 31 if descr(pB, "imgB" as *u8, hB) != 0 { fail = 1 } 32 33 if fail == 0 { 34 let self: i64 = chi2(hA, hA, 1000) 35 let ab: i64 = chi2(hA, hB, 1000) 36 lp("chi2(A,A)="); ln(self); lp(" expect 0 chi2(A,B)="); ln(ab); lp(" expect >0 -> ") 37 if self == 0 { if ab > 0 { lp("PASS\n" as *u8) } else { lp("FAIL\n" as *u8); fail = 1 } } else { lp("FAIL\n" as *u8); fail = 1 } 38 } 39 40 if fail == 0 { lp("nx_lbp_img RUNG2 GREEN (real PNG -> gray -> LBP descriptor; self=0, distinct>0)\n" as *u8); sys_exit(0); return 0 } 41 lp("nx_lbp_img RUNG2 RED\n" as *u8); sys_exit(1); return 1 42}