"""Render mixed-stream synthetic diagnostic."""
import json,html
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1];OUT=ROOT/'results/l55';rs=json.loads((OUT/'results.json').read_text())['records'];modes=('original','original_clahe','overlap_contrast','overlap_then_clahe','overlap_interleave_clahe','three_stream')
def table(xs):
 rows=''
 for m in modes:
  vals=[sum(x['scores'][m]['budgets'][str(n)]['matched'] for x in xs) for n in (5,10,20)]+[sum(x['scores'][m]['all']['matched'] for x in xs)];cnt=sum(x['scores'][m]['retained'] for x in xs);rows+=f'<tr><td>{m}</td>'+''.join(f'<td>{v}</td>' for v in vals)+f'<td>{cnt}</td></tr>'
 return rows
cards=''
for x in rs:
 den=len(x['source_ids']);vals=', '.join(f"{m} {x['scores'][m]['budgets']['10']['matched']}/{den}" for m in ('original_clahe','overlap_contrast','overlap_interleave_clahe','three_stream'));cards+=f'<article><h2>{html.escape(x["condition"])} · pair {x["pair"]}</h2><img src="{x["image"]}" alt="Synthetic targets and mixed-stream segmentation rankings"><p>Top-10 matches: {vals}. <a href="{x["source_archive"]}">Original planes</a> · <a href="{x["clahe_archive"]}">CLAHE candidates</a> · <a href="{x["contrast_archive"]}">Contrast-box candidates</a>.</p></article>'
page='''<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Combining candidate streams</title><style>body{font:16px/1.5 system-ui;background:#f3f6ef;color:#203a38}main{max-width:1520px;margin:auto;padding:24px}.notice{background:#fff2d6;padding:16px}article{background:white;padding:14px;margin:16px 0}img{width:100%}table{border-collapse:collapse}th,td{padding:8px;border:1px solid #aaa;text-align:left}.table{overflow:auto}</style><main><nav><a href="/results/performance/">Performance monitor</a> · <a href="/research/L55.md">Research notes</a></nav><h1>Do enhanced and contrast candidates complement each other?</h1><p class="notice">Exploratory reanalysis on the same previously examined artificial scenes. Synthetic masks and additive blur do not establish real-slide, species or human-level performance. Three source pairs recur across conditions.</p><p>We combine saved original-detector, CLAHE-detector, and detector-overlap-ranked contrast-box masks. The mixed variants either append CLAHE after the overlap-ranked list, alternate that list with CLAHE, or cycle through the three individual streams. Each uses mask IoU ≥0.8 suppression, preserving raw masks and aliases; one-to-one target IoU ≥0.5 is evaluated after ranking. Previously computed five-plane detector, CLAHE and contrast model inference is excluded from ranking time. Original high-resolution pixels remain separate for classification.</p><h2>Nine crossing scenes: 18 synthetic targets</h2><div class="table"><table><tr><th>Method</th><th>Top 5</th><th>Top 10</th><th>Top 20</th><th>All</th><th>Retained</th></tr>ROWS</table></div><p>Background-only fields include unlabeled natural structures; candidate counts are not false positives. <a href="protocol.json">Frozen exploratory protocol</a> · <a href="results.json">Full scores and candidate orderings</a>. Public foreground: Gündüz et al., <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>; provenance in <a href="/results/r62/">R62</a>.</p>CARDS</main></html>'''.replace('ROWS',table([x for x in rs if x['condition'].startswith('crossing_')])).replace('CARDS',cards);(OUT/'index.html').write_text(page)
