import html,json
from pathlib import Path
R=Path(__file__).resolve().parents[1];O=R/'results/l88';rows=json.loads((O/'results.json').read_text())['records'];base={(x['pair'],x['condition']):x for x in json.loads((R/'results/l75/results.json').read_text())['records']};tables=[]
for split in ('development','holdout_source_fields'):
 for cond in ('separated','crossing','near','partial'):
  a=[x for x in rows if x['split']==split and x['condition']==cond];v=[sum(base[x['pair'],x['condition']]['scores']['quality']['30']['visible']['0.5']['matched'] for x in a),sum(x['scores']['tiled']['30']['0.5']['matched'] for x in a),sum(x['scores']['tiled']['all']['0.5']['matched'] for x in a),sum(x['scores']['eligible']['0.5']['matched'] for x in a),sum(x['scores']['raw']['0.5']['matched'] for x in a)];tables.append(f'<tr><td>{html.escape(split)}</td><td>{cond}</td>'+''.join(f'<td>{n}/4</td>' for n in v)+'</tr>')
cards=[]
for x in rows:
 b=base[x['pair'],x['condition']];bb=b['scores']['quality']['30']['visible']['0.5']['matched'];t=x['scores']['tiled']['30']['0.5']['matched'];raw=x['scores']['raw']['0.5']['matched'];cards.append(f'<section><h2>Pair {x["pair"]}: {html.escape(x["condition"])}</h2><p>Whole-image top 30: {bb}/2; tiled top 30: {t}/2; tiled raw candidates: {raw}/2. Tiled candidates kept: {x["kept_count"]}, of which {x["edge_kept_count"]} touch a tile boundary.</p><a href="{x["panel"]}"><img loading="lazy" src="{x["panel"]}" alt="Source supports and whole-image and tiled mask overlays"></a><p><a href="/results/l75/{x["source_image"]}">Original image</a> · <a href="{x["archive"]}">Tiled masks, crop and prompt coordinates</a></p></section>')
(O/'index.html').write_text('''<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>L88 tiled prompts</title><style>body{font:16px/1.5 system-ui;color:#18342f;max-width:1200px;margin:2em auto;padding:0 1em}a{color:#006b59}img{width:100%}table{border-collapse:collapse}td,th{border:1px solid #bbc;padding:.4em}.warn{background:#fff2d6;padding:1em}section{border-top:1px solid #ccd}</style><a href="/results/board.html">Research board</a> · <a href="/results/r100/">Background controls</a><h1>L88: Overlapping tile prompts</h1><p class="warn">Exploratory replay of previously examined synthetic scenes. Former source-field holdout is no longer untouched; opaque composites do not simulate real optics. Results do not establish real-overlap accuracy or human-level segmentation.</p><p>Each original 512×512 scene is divided into sixteen overlapping 256×256 crops; each crop is doubled for MobileSAM and receives 16 fixed local point prompts. The resulting masks are mapped back into original coordinates and can be truncated at crop boundaries. Compare the cached original whole-image 256-point grid with the 256 tiled prompts, using the same quality, area and cross-mask NMS thresholds. Tiles require <strong>16 image encodings per field</strong>, versus one for the whole image; context and scale also differ.</p><table><tr><th>Previous split</th><th>Scene</th><th>Whole image top 30</th><th>Tiled top 30</th><th>Tiled all after NMS</th><th>Tiled all eligible</th><th>Tiled all raw</th></tr>'''+''.join(tables)+'''</table><p>Scores are one-to-one matches to four inserted visible supports per row at IoU ≥0.5. In former-holdout crossing scenes, tiled raw and eligible pools contain matches for all 4/4 supports, compared with 2/4 in the earlier raw whole-image diagnostic. After NMS only 2/4 remain, and neither method matches a support in the first 30. The apparent raw availability is reference-assisted, not a deployable selection rule. Development near scenes improved from 2/4 to 4/4 at top 30; these small viewed cases are not independent validation.</p><p>A posthoc alias audit found each of the two newly available crossing-support masks was suppressed by an overlapping candidate with target IoU just below 0.5 (0.483 and 0.489); the suppressed masks' IoUs were 0.508 and 0.538. These threshold-sensitive boundary differences are not proof of a distinct-cell identity error. Retaining all eligible masks preserves 4/4 but still gives 0/4 in the first 60 by the existing quality order. The audit uses source references after inference and is not a frozen selection policy.</p><p>Across the 16 scenes, 1,800 tiled masks survived NMS; 1,203 touched a crop edge. The busy background has other unlabeled structures and diatoms, so candidate volume is not a false-positive count. Cropping can truncate objects, and a suppressed-mask alias must remain reversible. Native images and source coordinates are retained for later species-level work.</p><p>Source/archive hashes, crop and point coordinates, mapped mask bounds, eligibility, shared NMS and matching were reconstructed; verification did not rerun all inference. Eight selected tile queries were separately rerun and their mapped masks matched the saved results exactly. The retrospective alias diagnostic was replayed byte-identically but shares the matcher.</p><p><a href="protocol.json">Protocol</a> · <a href="results.json">All ranks and scores</a> · <a href="alias-diagnostic.json">Posthoc alias audit</a> · <a href="verify.log">Verification</a> · <a href="sample-replay.json">Sample inference replay</a> · <a href="/research/L88.md">Research note</a></p>'''+''.join(cards)+'</html>')
