Compare Screenshots
Decide which image is less wrong against what the scene should show — not
whether the candidate matches the baseline. The baseline is just an earlier
attempt; it can be wrong too. Treat both images as candidates measured against
a target you establish yourself. Metrics locate where the images differ; they
never decide who is right.
Workflow
- Establish the target from first principles. Before looking at distance,
decide what this image should show: the visual requirement, the design
intent, what the thing depicts in reality, and any domain skill that owns the
look. This — not the baseline — is ground truth. Write it down in one or two
concrete sentences ("low sun should cast long shadows east; trees fill the
canopy; labels stay legible at this zoom").
- If the right answer isn't clear — competing valid readings, a taste or
product-intent call, a tradeoff only the owner can settle — stop and ask
the user what the correct answer should be. Show them the comparison.
Do not quietly default to the baseline to avoid asking; that bakes in
whatever the baseline got wrong.
- Confirm comparability so the differences you see are real, not capture
artifacts: same viewport, DPR, route/page, frozen time/tick, camera intent,
UI state, data, fonts/assets where they matter. If not comparable, fix
capture setup or compare only a crop/feature where the mismatch is harmless.
- Generate artifacts to locate divergence, sized to the question:
side-by-side, key-feature crops/zooms, grayscale, absolute grayscale heatmap,
pixelmatch diff, per-image Sobel/edge maps, edge-difference heatmap, JSON
metrics.
- Judge each divergence against the target. For every place the two images
differ, name what is actually there in plain terms — missing content, wrong
camera, bad hierarchy, weak contrast, wrong depth, text overlap, layout
shift, clipped edge, unexpected blur, style mismatch — and decide which side
is closer to correct. The answer can be the candidate, the baseline, both
wrong, or a genuine toss-up.
- Get a neutral second opinion for disputed or high-stakes calls: a fresh
subagent given only the two images and neutral labels, per
references/subagent-visual-review.md.
- Conclude with one verdict: candidate is less wrong (accept, and re-bless
the baseline if one exists), baseline is less wrong (reject), both wrong
(another pass needed — say what's still off), or unclear (ask the user).
Never accept on a lower score alone or reject on a higher one. Never hide
content, blur detail, crop away differences, or make the capture less
truthful to move a number.
Useful Metrics
Pick metrics that answer the question. For full visual comparisons, report:
mae: mean absolute grayscale difference, 0..255, lower is closer.
rmse: grayscale root mean square error, lower is closer.
diffRatio16, diffRatio32, diffRatio64: fraction of pixels over each
grayscale delta threshold.
pixelmatchRatio: mismatch ratio from pixelmatch over grayscale images.
edgeEnergyCurrent and edgeEnergyCandidate: average Sobel edge strength.
edgeEnergyRatio: candidate/current. Far below 1 usually means missing
geometry, props, labels, or terrain; far above 1 usually means noisy or
incorrect detail.
edgeDiffRatio32: fraction of pixels whose Sobel edge differs materially.
avgLuminanceCurrent, avgLuminanceCandidate, avgLuminanceDelta: average
brightness and delta. Use when a render is visibly too dark/light even if a
broader distance score improves.
- Content proxies relevant to the scene: black/void ratio, terrain-like ratio,
water-like ratio, team-color ratio, label/text mask ratio.
For UI/document/layout reviews, also use crop bounds, text/foreground mask
coverage, contrast checks, edge clipping, element positions, and before/after
dimensions when those beat global pixel distance.
Single-Image Metrics
Every metric above measures one image against another, so none of them can
answer "is this capture worth anything" when there is nothing to compare it to
— and the pair score is symmetric, so an enormous distance never says which
side is the empty frame. A few absolute numbers do, computed on a coarse grid
from a single PNG:
colorEntropyBits under ~3.0, or dominantColorShare over ~0.6: one colour
owns the frame. A sparse scene, an unlit one, or a subject that never drew.
edgeDensity under ~0.04: almost no form anywhere. Empty framing, a
primitive-dominant scene, or the subject sitting outside the crop.
luminanceContrast under ~60: fog, darkness, or haze compressing the whole
frame into one band.
transparentShare above 0 on a capture that should be opaque: the capture
itself is wrong. A transparent pixel keeps whatever RGB it was left with, so
an invisible frame can look rich until it is composited — the scene metrics
composite before measuring, and name the invisible share rather than letting
you infer it. The pair metrics above still read stored RGB, so this field is
where transparency gets told either way.
These are thresholds for suspicion, not gates. A deliberately minimal design,
a night scene, an empty-state screen, and a whiteboard all trip them honestly.
Use them to decide where to look, then say what the frame is actually doing —
never adjust a capture to raise a number, which is the same failure as cropping
away a difference.
Distance Score
When a single fixed-pair number is useful, this default works for structural
changes:
distance = 0.35 * diffRatio32 + 0.25 * pixelmatchRatio + 0.25 * edgeDiffRatio32 + 0.15 * min(1, abs(log2(edgeEnergyRatio)))
It measures distance from the other image, nothing more. Because the
baseline can be wrong, a distance of 0 is not success and a large distance is
not failure — a richer scene, clearer models, stronger labels, real depth, or
better lighting all legitimately raise it. Use the score to find where the
images move; decide who is right in step 4. Name the field for what it measures
(distance, not "parity") so no one reads it as a verdict.
Report the full-frame score and, when UI dominates the shot, a labeled
world-crop score. Use the world-crop score to locate renderer movement and keep
the full-frame score so UI/camera mistakes stay visible.
Score Discipline
- Quote the previous and new distance for the same pair each iteration, then say
whether the movement is toward the target, away from it, or diagnostic noise.
- Prefer edge metrics for missing-content bugs. A flat top-down map can show a
deceptively moderate grayscale diff while edge energy proves trees, roads,
city forms, or army silhouettes are absent.
- Segment out stable UI when it dominates and the question is the world render;
keep a full-frame score too, labeled.
- If the camera is wrong, pixel scores are diagnostic only. Fix camera intent
first, then judge the render.
Tooling
Keep comparison scripts inside the skill or a temporary workspace, not in
product code, unless the product genuinely needs screenshot comparison at
runtime.
scripts/visual-parity-diff.mjs is a reusable local helper. Run it with
REFERENCE_DIR=<png-folder>, CANDIDATE_DIR=<png-folder>, and optional
OUT_DIR=<artifact-folder>. REPORT_ORDER=a,b,c pins ordering;
CROPS_JSON=<file> adds labeled crops (keyed by image id, each crop in pixels
or { "unit": "ratio" } normalized bounds). Pair reports carry a
sceneMetrics block per side.
- Drop
REFERENCE_DIR to run the same helper on a folder with no counterpart:
it writes scene-metrics.json with the single-image numbers above and no
diff artifacts. Use it on a lone screenshot, on a full capture set before
anyone reviews it, or to find which side of a large distance is the empty
one.
scripts/visual-parity-diff.eval.mjs is the helper's own eval: it generates
fixtures whose correct answer is known by construction — empty, transparent,
primitive-dominant, authored, degenerate — and asserts the classification,
the invariances, and the CLI contract. Run it with the same REPO_ROOT after
changing the script. Never satisfy a failing check by loosening a threshold
until you have shown the fixture, not the code, is what's wrong.
- For other tasks, adapt the same artifact set rather than adding one-off
scripts to the application. Extend the helper if a needed pair is uncovered.
References
references/subagent-visual-review.md: neutral subagent prompt/config for an
independent judgment when history could bias you.
1---2name: compare-screenshots-23description: Compare screenshots to judge which image is less wrong, not to match a baseline. Use when a UI, game, document, render, chart, or generated asset needs objective visual telemetry, side-by-side inspection, crop/zoom review, or a fresh second opinion before accepting or rejecting a visual change. Also use on a single capture with no counterpart, to measure whether the frame is flat, empty, or badly framed before anyone reviews it.4---56# Compare Screenshots78Decide which image is **less wrong** against what the scene should show — not9whether the candidate matches the baseline. The baseline is just an earlier10attempt; it can be wrong too. Treat both images as candidates measured against11a target you establish yourself. Metrics locate where the images differ; they12never decide who is right.1314## Workflow15161. **Establish the target from first principles.** Before looking at distance,17 decide what this image *should* show: the visual requirement, the design18 intent, what the thing depicts in reality, and any domain skill that owns the19 look. This — not the baseline — is ground truth. Write it down in one or two20 concrete sentences ("low sun should cast long shadows east; trees fill the21 canopy; labels stay legible at this zoom").22 - If the right answer isn't clear — competing valid readings, a taste or23 product-intent call, a tradeoff only the owner can settle — **stop and ask24 the user** what the correct answer should be. Show them the comparison.25 Do not quietly default to the baseline to avoid asking; that bakes in26 whatever the baseline got wrong.272. **Confirm comparability** so the differences you see are real, not capture28 artifacts: same viewport, DPR, route/page, frozen time/tick, camera intent,29 UI state, data, fonts/assets where they matter. If not comparable, fix30 capture setup or compare only a crop/feature where the mismatch is harmless.313. **Generate artifacts to locate divergence**, sized to the question:32 side-by-side, key-feature crops/zooms, grayscale, absolute grayscale heatmap,33 pixelmatch diff, per-image Sobel/edge maps, edge-difference heatmap, JSON34 metrics.354. **Judge each divergence against the target.** For every place the two images36 differ, name what is actually there in plain terms — missing content, wrong37 camera, bad hierarchy, weak contrast, wrong depth, text overlap, layout38 shift, clipped edge, unexpected blur, style mismatch — and decide which side39 is closer to correct. The answer can be the candidate, the baseline, both40 wrong, or a genuine toss-up.415. **Get a neutral second opinion** for disputed or high-stakes calls: a fresh42 subagent given only the two images and neutral labels, per43 `references/subagent-visual-review.md`.446. **Conclude with one verdict:** candidate is less wrong (accept, and re-bless45 the baseline if one exists), baseline is less wrong (reject), both wrong46 (another pass needed — say what's still off), or unclear (ask the user).47 Never accept on a lower score alone or reject on a higher one. Never hide48 content, blur detail, crop away differences, or make the capture less49 truthful to move a number.5051## Useful Metrics5253Pick metrics that answer the question. For full visual comparisons, report:5455- `mae`: mean absolute grayscale difference, 0..255, lower is closer.56- `rmse`: grayscale root mean square error, lower is closer.57- `diffRatio16`, `diffRatio32`, `diffRatio64`: fraction of pixels over each58 grayscale delta threshold.59- `pixelmatchRatio`: mismatch ratio from pixelmatch over grayscale images.60- `edgeEnergyCurrent` and `edgeEnergyCandidate`: average Sobel edge strength.61- `edgeEnergyRatio`: candidate/current. Far below 1 usually means missing62 geometry, props, labels, or terrain; far above 1 usually means noisy or63 incorrect detail.64- `edgeDiffRatio32`: fraction of pixels whose Sobel edge differs materially.65- `avgLuminanceCurrent`, `avgLuminanceCandidate`, `avgLuminanceDelta`: average66 brightness and delta. Use when a render is visibly too dark/light even if a67 broader distance score improves.68- Content proxies relevant to the scene: black/void ratio, terrain-like ratio,69 water-like ratio, team-color ratio, label/text mask ratio.7071For UI/document/layout reviews, also use crop bounds, text/foreground mask72coverage, contrast checks, edge clipping, element positions, and before/after73dimensions when those beat global pixel distance.7475## Single-Image Metrics7677Every metric above measures one image against another, so none of them can78answer "is this capture worth anything" when there is nothing to compare it to79— and the pair score is symmetric, so an enormous distance never says *which*80side is the empty frame. A few absolute numbers do, computed on a coarse grid81from a single PNG:8283- `colorEntropyBits` under ~3.0, or `dominantColorShare` over ~0.6: one colour84 owns the frame. A sparse scene, an unlit one, or a subject that never drew.85- `edgeDensity` under ~0.04: almost no form anywhere. Empty framing, a86 primitive-dominant scene, or the subject sitting outside the crop.87- `luminanceContrast` under ~60: fog, darkness, or haze compressing the whole88 frame into one band.89- `transparentShare` above 0 on a capture that should be opaque: the capture90 itself is wrong. A transparent pixel keeps whatever RGB it was left with, so91 an invisible frame can look rich until it is composited — the scene metrics92 composite before measuring, and name the invisible share rather than letting93 you infer it. The pair metrics above still read stored RGB, so this field is94 where transparency gets told either way.9596These are thresholds for *suspicion*, not gates. A deliberately minimal design,97a night scene, an empty-state screen, and a whiteboard all trip them honestly.98Use them to decide where to look, then say what the frame is actually doing —99never adjust a capture to raise a number, which is the same failure as cropping100away a difference.101102## Distance Score103104When a single fixed-pair number is useful, this default works for structural105changes:106107`distance = 0.35 * diffRatio32 + 0.25 * pixelmatchRatio + 0.25 * edgeDiffRatio32 + 0.15 * min(1, abs(log2(edgeEnergyRatio)))`108109It measures **distance from the other image**, nothing more. Because the110baseline can be wrong, a distance of 0 is not success and a large distance is111not failure — a richer scene, clearer models, stronger labels, real depth, or112better lighting all legitimately raise it. Use the score to find *where* the113images move; decide who is right in step 4. Name the field for what it measures114(distance, not "parity") so no one reads it as a verdict.115116Report the full-frame score and, when UI dominates the shot, a labeled117world-crop score. Use the world-crop score to locate renderer movement and keep118the full-frame score so UI/camera mistakes stay visible.119120## Score Discipline121122- Quote the previous and new distance for the same pair each iteration, then say123 whether the movement is toward the target, away from it, or diagnostic noise.124- Prefer edge metrics for missing-content bugs. A flat top-down map can show a125 deceptively moderate grayscale diff while edge energy proves trees, roads,126 city forms, or army silhouettes are absent.127- Segment out stable UI when it dominates and the question is the world render;128 keep a full-frame score too, labeled.129- If the camera is wrong, pixel scores are diagnostic only. Fix camera intent130 first, then judge the render.131132## Tooling133134Keep comparison scripts inside the skill or a temporary workspace, not in135product code, unless the product genuinely needs screenshot comparison at136runtime.137138- `scripts/visual-parity-diff.mjs` is a reusable local helper. Run it with139 `REFERENCE_DIR=<png-folder>`, `CANDIDATE_DIR=<png-folder>`, and optional140 `OUT_DIR=<artifact-folder>`. `REPORT_ORDER=a,b,c` pins ordering;141 `CROPS_JSON=<file>` adds labeled crops (keyed by image id, each crop in pixels142 or `{ "unit": "ratio" }` normalized bounds). Pair reports carry a143 `sceneMetrics` block per side.144- Drop `REFERENCE_DIR` to run the same helper on a folder with no counterpart:145 it writes `scene-metrics.json` with the single-image numbers above and no146 diff artifacts. Use it on a lone screenshot, on a full capture set before147 anyone reviews it, or to find which side of a large distance is the empty148 one.149- `scripts/visual-parity-diff.eval.mjs` is the helper's own eval: it generates150 fixtures whose correct answer is known by construction — empty, transparent,151 primitive-dominant, authored, degenerate — and asserts the classification,152 the invariances, and the CLI contract. Run it with the same `REPO_ROOT` after153 changing the script. Never satisfy a failing check by loosening a threshold154 until you have shown the fixture, not the code, is what's wrong.155- For other tasks, adapt the same artifact set rather than adding one-off156 scripts to the application. Extend the helper if a needed pair is uncovered.157158## References159160- `references/subagent-visual-review.md`: neutral subagent prompt/config for an161 independent judgment when history could bias you.