run_pixel_boundary_localization_050.py VOYNICH RESEARCH ARCHIVE | 16 SEPTEMBER 2026 1 run_pixel_boundary_localization_050.py Source: /Voynich/Voynich_PIXEL_BOUNDARY_LOCALIZATION_050_reproducibility.zip!/run_pixel_boundary_localiz ation_050.py SHA-256: 5e8a8eeefee44b21e68bc6cfde101eb7c42768f4c324b6dc7edc525dfe6272f2 !/usr/bin/env python3 """PIXEL-BOUNDARY-LOCALIZATION-050: within-token physical localization of R->L atom boundaries.""" from pathlib import Path from collections import defaultdict import hashlib,json,math,re import fitz,numpy as np,pandas as pd from scipy import ndimage import run_pixel_nested_frame_049 as p49 import run_citation_dictionary_027 as c27 ROOT=Path(__file__).resolve().parent; OUT=ROOT/'pixel_boundary_localization_050'; OUT.mkdir(exist_ok=True) PDF=p49.PDF; BOX=p49.BOX; SEED=20260830; REPS=1000 def crop_profile(gray,b): h,w=gray.shape;sx=w/600;sy=h/837 x0=max(0,int((b.x-2)*sx));x1=min(w,int((b.x+b.w+2)*sx));y0=max(0,int((b.y-2)*sy));y1=min(h,int((b.y+b.h +2)*sy));c=gray[y0:y1,x0:x1] if c.size<30:return None ink=c0 else c r=col[min(w,x+center+1):min(w,x+center+1+should)].mean() if x+center+1best:best=float(s);bestx=x return best,float(bestx/w),float(nom/w) def main(): lines,meta=p49.parse();boxes=pd.read_csv(BOX);doc=fitz.open(PDF);pm=p49.pages();by=defaultdict(list) for r in boxes.itertuples():by[r.folio].append(r) rows=[];invalid=0;tokens=0 for fol,bb in by.items(): if fol not in pm:continue pix=doc[pm[fol]].get_pixmap(matrix=fitz.Matrix(4,4),colorspace=fitz.csGRAY,alpha=False);gray=np.frombu ffer(pix.samples,dtype=np.uint8).reshape(pix.height,pix.width) for b in bb: z=lines.get((fol,int(b.line))) if z is None or int(b.index)>=len(z):continue a=z[int(b.index)];eligible=list(range(1,len(a)-2));pred=[i for i in eligible if a[i] in c27.R and a[i+1] in c27.L] if not pred or len(eligible)==len(pred):continue col=crop_profile(gray,b) if col is None:invalid+=1;continue tid=f'{fol}:{int(b.line)}:{int(b.index)}';tokens+=1 for i in eligible: score,x,nom=boundary_score(col,i+1,len(a));rows.append({'token_id':tid,'folio':fol,'line':int(b.line ),'index':int(b.index),'hand':meta.get(fol,{}).get('H','?'),'currier':meta.get(fol,{}).get('L','?'),'sec tion':p49.sec(fol),'surface':' '.join(a),'atom_count':len(a),'boundary_after_index':i,'left_atom':a[i],' right_atom':a[i+1],'predicted_rl':int(i in pred),'valley_score':score,'localized_x':x,'nominal_x':nom}) d=pd.DataFrame(rows);d.to_csv(OUT/'boundary_events.csv',index=False) def dif(g,lab='predicted_rl'):