import html,json
from pathlib import Path
R=Path(__file__).resolve().parents[1];O=R/'results/r106';rows=json.loads((O/'results.json').read_text())['records'];total=sum(x['references'] for x in rows);methods=('original','defer_padding','valid_first','historical');tables=[]
for t in ('0.5','0.75'):
 for n in ('10','30','60','all'):
  vals=[sum(x['scores'][k][n]['all'][t]['matched'] for x in rows) for k in methods];tables.append(f'<tr><td>{t}</td><td>{n}</td>'+''.join(f'<td>{v}/{total}</td>' for v in vals)+'</tr>')
cards=[]
for r in rows:
 vals=[r['scores'][k]['10']['all']['0.5']['matched'] for k in methods];pad=[r['display_counts'][k]['10']['padding_points'] for k in methods[:3]];cards.append(f'<section><h2>Source field {html.escape(r["id"])}</h2><p>Top 10 matches: original / deferred / valid-first / historical = {" / ".join(map(str,vals))} of {r["references"]}. Shown padding-prompt masks (first three): {" / ".join(map(str,pad))}. Used in separate R54 decoder training: {"yes" if r["used_for_r54_training"] else "no"}; that decoder is not used here.</p><a href="{html.escape(r["panel"])}"><img loading="lazy" src="{html.escape(r["panel"])}" alt="Source regions and original, padding-deferred and historical candidate overlays"></a><p><a href="/{html.escape(r["source"])}">Original source RGB</a> · <a href="{html.escape(r["archive"])}">All tiled masks and points</a> · <a href="/results/r97/{html.escape(r["r97_archive"])}">Reference archive</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>R106 padding-aware source replay</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/l90/">Earlier padding diagnosis</a> · <a href="/results/r97/">Source history</a><h1>R106: Frozen padding deferral on other public image files</h1><p class="warn">Different source files, but all were previously viewed; biological samples, slides and pretrained-model exposure are not established independent. Sixteen fields were used to train a separate R54 decoder, which is not used here. Source reference regions exclude intersecting boxes and cannot validate severe real overlap or human-level segmentation.</p><p>Run fixed L89 variance-guided tiled points on 23 R97-retained public Gündüz fields. The unchanged score-ranked NMS stream is compared with stable padding deferral, which puts in-image prompts first while retaining every originally kept candidate. Valid-first NMS separately suppresses among in-image prompts then appends all remaining eligible masks, including padding candidates. The historical detector/grid-SAM + Cellpose-DINO stream used different models, proposals, image scale and compute.</p><table><tr><th>Mask IoU ≥</th><th>Budget per field</th><th>Original tiles</th><th>Padding deferred</th><th>Valid-first NMS</th><th>Historical mixed</th></tr>'''+''.join(tables)+'''</table><p>Counts are one-to-one matches to 26 structural source regions. At top ten, the fixed deferral moves 18/26 to 21/26; the historical mixed stream matches 26/26 under different inference conditions. Deferral improves three fields and leaves 20 unchanged at IoU ≥0.5; the current small development group does not prove generalization. Raw tiled masks match 25/26 and therefore cannot recover one source region at this threshold even before filtering.</p><p>There were 537 padding points among 5,888 raw tile queries. Of 230 top-ten masks across fields, original lists contain 93 padding-prompt candidates, versus zero in both padding-aware orders. No mask is rejected solely because it touches an image boundary. Padding deferral preserves the entire original kept set; valid-first retains every eligible mask but changes early NMS ordering. Source annotations are incomplete, so padding-point candidates are not confirmed false positives and candidate counts do not measure actual human review time.</p><p>None of the 26 source regions have a bounding box within four pixels of the image-content border, our frozen geometric proxy. Consequently this study does not test partial edge-object recovery; real severe-overlap references are also absent.</p><p>The existing frozen similarity screens cover all selected fields against known YOLO training, earlier real/synthetic reference crops, and the 13 L90 development fields; no selected pair was flagged. This coarse screen can miss related specimens, and does not screen synthetic Academy backgrounds as whole slides. All source/reference/model-archive hashes, point selection, ranking, NMS and scores were reconstructed using shared point selector and matcher; eight sampled single-query replays reproduced their batched masks.</p><p>Source images: Hüseyin Gündüz, <a href="https://www.kaggle.com/datasets/huseyingunduz/diatom-dataset">Diatom Dataset</a>, CC BY-NC-SA 4.0; separate model/software terms apply. The historical stream's masks were inferred at 768×576 and resized for 512×384 scoring, with different models and costs.</p><p><a href="protocol.json">Protocol</a> · <a href="screen-check.json">Cross-source screen check</a> · <a href="results.json">Scores, ranks and masks</a> · <a href="verify.log">Verification</a> · <a href="sample-replay.json">Sample neural replay</a> · <a href="/research/R106.md">Research note</a></p>'''+''.join(cards)+'</html>')
