nx_imgsig.nx source
↩ module page · 34 lines · 1440 B
1// nx_imgsig.nx -- UNIFIED visual-appearance signature = nx_visdesc (structure/tone, 80-dim) concatenated
2// with nx_colordesc (chroma color-layout, 32-dim) -> a 112-dim integer vector ranked by L1. Because both
3// components are already on the same ~0..256 per-dimension scale, concatenation needs NO weighting or
4// renormalisation: one L1 over 112 dims jointly measures structural AND color similarity. This is the
5// "looks-alike" axis (Google-style); dHash (nx_phash) remains the orthogonal copy-detection axis
6// (Hamming) -- a reverse-image client uses dHash for exact/near copies and imgsig for visual similarity.
7//
8// Composes nx_visdesc + nx_colordesc -- ZERO new feature math. license_tier: ORIGINAL
9import "nx_visdesc.nx"
10import "nx_colordesc.nx"
11
12const SIG_DIM: i64 = 112 // 80 (visdesc) + 32 (colordesc)
13
14func nx_imgsig_dim() -> i64 { return SIG_DIM }
15
16// extract the 112-dim signature: out[0..80) = edge/tone (from gray), out[80..112) = chroma (from rgb).
17func nx_imgsig_extract(gray: *u8, rgb: *u8, w: i64, h: i64, out: *i64) -> i64 {
18 nx_visdesc_extract(gray, w, h, out)
19 let coff: *i64 = ((out as i64) + 80*8) as *i64
20 nx_colordesc_extract(rgb, w, h, coff)
21 return SIG_DIM
22}
23
24func nx_imgsig_l1(a: *i64, b: *i64) -> i64 {
25 var d: i64 = 0
26 var i: i64 = 0
27 while i < SIG_DIM {
28 var t: i64 = a[i] - b[i]
29 if t < 0 { t = 0 - t }
30 d = d + t
31 i = i + 1
32 }
33 return d
34}