# decryption_complete: false # source: /Voynich/render_external_anchor_label_crops_018.py # stated_sha256: 6acaeaf83c909b6f2f6973372d8d915db84b96346abc2f21a8a2c65c42092635 # matches_stated_sha256: false # pdf_pages: 140-141 # note: The stated SHA-256 is the digest printed in the PDF. # The PDF page extract follows the form feed. decryption_complete stays false. render_external_anchor_label_crops_018.py VOYNICH RESEARCH ARCHIVE | 16 SEPTEMBER 2026 1 render_external_anchor_label_crops_018.py Source: /Voynich/render_external_anchor_label_crops_018.py SHA-256: 6acaeaf83c909b6f2f6973372d8d915db84b96346abc2f21a8a2c65c42092635 !/usr/bin/env python3 """Render coordinate-level reveal crops for strict EXTERNAL-ANCHOR-ATTACK-018 candidates.""" import csv,re,math,json from collections import defaultdict from difflib import SequenceMatcher from pathlib import Path import fitz from PIL import Image,ImageDraw,ImageFont OUT=Path('external_anchor_attack_018') PDF=Path('library_scan/Voynich_Manuscript.pdf') BOX=Path('glyph_crop_atlas_001/aligned_token_boxes.csv') BOXDIR=Path('external_voynich_units/data/voynich-units/morphometry_voynichese/voynichese_boxes') EVA=Path('external_voynich_units/data/voynich-units/ZL3b.txt') MISSING={12,*range(59,65),74,91,92,97,98,109,110} def pagemap(): s=[] for n in range(1,117): if n not in MISSING:s += [f'f{n}r',f'f{n}v'] return {f:i+2 for i,f in enumerate(s)} def base(f):return re.sub(r'([rv])\d+$',r'\1',f) def collapse(s): for a,b in (('ckh','K'),('cth','T'),('cph','P'),('cfh','F'),('ch','C'),('sh','S'),('iin','N'),('ii','M' )):s=s.replace(a,b) return s def box_lines(path): data=json.loads(path.read_text());vocab=[x[0] for x in data[0]];lines=[];cur=[];px=None for e in data[1]: q={'word':vocab[e[0]],'x':e[1],'y':e[2],'w':e[3],'h':e[4]} if px is not None and q['x']]*L[^>]*>') out=defaultdict(list);bad=set('?*<>{}[]()|') for raw in EVA.read_text(errors='replace').splitlines(): m=pat.match(raw) if not m:continue body=re.sub(r'<[^>]*>','',raw[raw.find('>')+1:]);body=re.sub(r'\{[^}]*\}','',body).rstrip('-=').strip( );t=[] for q in re.split(r'[.,]',body): q=q.strip() if q and not(set(q)&bad):t.append(q) if t:out[m.group(1)].append((int(m.group(2)),t)) return out def aligned_label_boxes(): txt=eva_label_lines();out={} for p in BOXDIR.glob('*.js'): fol=p.stem if fol not in txt:continue vis=box_lines(p);used=set() for vi,vline in enumerate(vis): best=None for tj,(ln,tline) in enumerate(txt[fol]): if tj in used:continue ratio=SequenceMatcher(a=[collapse(x['word']) for x in vline],b=[collapse(x) for x in tline],autojunk=False).ratio() render_external_anchor_label_crops_018.py VOYNICH RESEARCH ARCHIVE | 16 SEPTEMBER 2026 2 if best is None or ratio>best[0]:best=(ratio,tj,ln,tline) if not best or best[0]<.5:continue _,tj,ln,tline=best;used.add(tj);sm=SequenceMatcher(a=[collapse(x['word']) for x in vline],b=[collapse(x) for x in tline],autojunk=False) for a,b,n in sm.get_matching_blocks(): for j in range(n):out[(fol,str(ln),str(b+j))]=vline[a+j] return out ranking=list(csv.DictReader((OUT/'frozen_candidate_ranking.csv').open())) strict={r['payload']:r['stem_id'] for r in ranking if r['strict_candidate_gate']=='1'} events=[r for r in csv.DictReader((OUT/'label_prose_events.csv').open()) if r['witness']=='ZL' and r['register']=='LABEL' and r['payload'] in strict] bmap=aligned_label_boxes() doc=fitz.open(PDF); pm=pagemap(); tiles=[]; font=ImageFont.load_default() for e in events: k=(e['folio'],e['line'],e['token_index']); b=bmap.get(k); bf=base(e['folio']) if not b or bf not in pm:continue pix=doc[pm[bf]].get_pixmap(matrix=fitz.Matrix(2.0,2.0),alpha=False) im=Image.frombytes('RGB',(pix.width,pix.height),pix.samples) sx=im.width/600;sy=im.height/837;x=float(b['x']);y=float(b['y']);w=float(b['w']);h=float(b['h']) # Wide context is deliberate: labels often point into diagrams/plants rather than sit inside them. x0=max(0,int((x-150)*sx));x1=min(im.width,int((x+w+150)*sx));y0=max(0,int((y-120)*sy));y1=min(im.height ,int((y+h+120)*sy)) crop=im.crop((x0,y0,x1,y1));crop.thumbnail((500,360)) tile=Image.new('RGB',(520,410),'white');tile.paste(crop,((520-crop.width)//2,42));d=ImageDraw.Draw(tile ) d.text((8,8),f"{strict[e['payload']]} [{e['payload']}] {e['folio']}.{e['line']} token {e['token_index']}",fill='black',font=font) tiles.append(tile) cols=2;rows=max(1,math.ceil(len(tiles)/cols));sheet=Image.new('RGB',(cols*520,rows*410),(225,229,233)) for i,t in enumerate(tiles):sheet.paste(t,((i%cols)*520,(i//cols)*410)) sheet.save(OUT/'strict_candidate_label_coordinate_reveal.jpg',quality=90) print({'strict_candidates':strict,'label_events':len(events),'matched_crops':len(tiles)})