"""Publish a small preselected visual inspection of projected mask proposals."""
import html,json
from pathlib import Path
R=Path(__file__).resolve().parents[1];O=R/'results/r112/mask-uncertainty';r=json.loads((O/'results.json').read_text());tot=r['totals'];n=sum(tot[f'vote_{i}_instance_pixels'] for i in (1,2,3));cases=[]
for item in r['records']:
 if 'comparison_image' not in item:continue
 x=item['instances'][0]; h=x['proposal_vote_pixels_1_2_3'];cases.append('<article><h3>'+html.escape(item['manifest'].split('/')[-2])+' / '+html.escape(item['scene_id'])+'</h3><p>First inserted candidate: '+html.escape(x['source_species'])+' ('+html.escape(x['annotation_id'])+'). Votes in the frame: 1 / 2 / 3 = '+(' / '.join(map(str,h)))+' instance-pixels.</p><a href="'+html.escape(item['comparison_image'])+'"><img loading="lazy" src="'+html.escape(item['comparison_image'])+'" alt="Scene and first placement with proposal agreement overlay"></a></article>')
page='''<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Source-mask proposal views</title><style>body{font:16px/1.55 system-ui;background:#f4f6f0;color:#193b37;margin:0}main{max-width:1050px;margin:auto;padding:24px}a{color:#096c58}.notice,article{background:white;border:1px solid #cddbd2;padding:16px;margin:14px 0}.notice{border-left:5px solid #bc851b}img{max-width:100%;height:auto}pre{overflow:auto;background:#edf3ef;padding:12px}</style><body><main><nav><a href="/results/r112/">Synthetic training</a> · <a href="/results/r112/dataset-interface/">Dataset reader</a></nav><h1>Inspecting alternative source-mask proposals</h1><p class="notice"><strong>Agreement is not ground truth.</strong> Three prompts were evaluated by the same model, so all three can agree on the wrong specimen or background. The source names and masks remain unverified; these votes are not calibrated probabilities. All original Academy background pixels remain unknown.</p><p>The reader projects all three source-mask hypotheses for each of '''+str(tot['instances'])+''' placements across '''+str(r['scenes'])+''' scenes. Each placement has at least one in-frame pixel on which the masks disagree. Across the union of individual proposals, '''+f"{100*(tot['vote_1_instance_pixels']+tot['vote_2_instance_pixels'])/n:.1f}"+'''% of instance-pixels have one or two votes; overlapping placements count separately. This does not measure anatomical error.</p><p>Only the center proposal was used when rendering the actual synthetic image. Alternate boundaries are counterfactual mask hypotheses: an alternate can extend beyond pixels where the synthetic source was added. They are not three separate observations of the rendered scene, a visibility model, or a verified target for training.</p><p>The examples below were selected by position in the existing scene lists, before counting disagreement. Teal marks pixels covered by all three proposals for the <em>first placement only</em>; amber marks one or two. Other insertions and any diatoms already in the background are not outlined.</p><pre>dataset = WeakSceneDataset(include_mask_variants=True)
scene = dataset[0]
proposals = scene["weak_mask_proposals"]   # instances × 3 × H × W
votes = scene["weak_mask_vote_count"]      # instances × H × W, 0–3
unknown = scene["unknown_region"]          # all True</pre><p><a href="results.json">All proposal counts and provenance</a> · <a href="verify.json">Reconstruction checks</a> · <a href="/diatom_pilot/weak_scene_dataset.py">Reader source</a></p>'''+''.join(cases)+'''</main></body></html>''';(O/'index.html').write_text(page);print('published',len(cases),'examples')
