DOGMA Source Evidence Gate v25 — Anti-Hallucination
Don't let the model invent detail where the source is flat
- generated
- source
- image
- evidence_weight
- info
Generative upscaling has one failure mode that isn't obvious until you compare against the source: it invents. Detail where there was none, texture on skin, windows on a wall, a pedestrian in an empty lane. The community cheerfully calls it hallucination, and it's the reason upscaling.md lists "structure-preserving condition" as the thing that stops tiles diverging, and why control-tile workflows beat bare tiled diffusion.
This node is a post-hoc version of that idea. You hand it the generated result and the source, and it decides - per pixel - how much of the generated version to keep, based on how much real evidence existed in the source at that spot.
The mechanism
Both images get downsampled to a small proxy (256px by default - analysis here is cheap compared to sampling, and at this scale you're measuring structure, not detail). From the source proxy it computes a luminance map, then two signals:
- local gradient magnitude (max of horizontal and vertical finite differences), and
- local deviation: how far each pixel's luminance sits from a 7×7 box average, multiplied by 1.5.
It takes the max of those two as evidence. Real edges and real texture score high; uniform sky, glass, fog and shadow fields score near zero. That evidence is then normalized into a 0–1 gate between low_threshold and high_threshold, grown outward with a max-pool of radius support_grow so that an edge's neighbourhood counts as evidence too, and smoothed with a 5×5 average. Upsample the gate back to full resolution and you have a per-pixel alpha:
alpha = flat_generated_weight + (1 - flat_generated_weight) * gate
out = source * (1 - alpha) + generated * alpha
So in flat regions alpha collapses to flat_generated_weight - 0.10 by default, meaning 90% source - and wherever real structure existed, alpha climbs toward 1.0 and the generated reconstruction wins. The node hands back the alpha channel too, as evidence_weight, which is genuinely useful: preview it and you're looking at a map of where your model got to improvise.
Inputs and outputs
generated (IMAGE), source (IMAGE) - the source is interpolated to match if the sizes differ, and expanded if you pass fewer frames than the generated batch. Then flat_generated_weight (default 0.10, 0–0.8), low_threshold (0.010), high_threshold (0.045), proxy_long_side (256, range 96–512, step 32), support_grow (5, range 0–16).
Outputs: image (IMAGE), evidence_weight (MASK), info (STRING, reporting the proxy size, the floor value, and the mean alpha).
Wire image downstream as your gated result. evidence_weight is worth a Preview node - if it's all near flat_generated_weight, your thresholds are too high for this image and you've just thrown away the model's work.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/axior/ComfyUI-DOGMA-Nodes
Or ComfyUI Manager → DOGMA Nodes, or comfy node install comfyui-dogma-nodes. No Python dependencies: requirements.txt is one comment line, pyproject.toml declares dependencies = [], and this runs on torch alone. No model files, no downloads. MIT licensed.
Where people get burned
It's a source-fidelity gate, not a quality gate. If your generated tile is worse than the source because the model drifted, this helps. If it's better and the source is genuinely detailed, the gate will happily keep it. That's the correct behaviour and it isn't the same as "make this look better."
Analysis at 256px misses small structure. The proxy is deliberately tiny so the cost is negligible next to a sampling pass. But a thin wire, a distant figure, fine text - all of that flattens out at 256px and gets treated as flat, which means your generated version of it gets suppressed 90% to source. On a hi-res plate where small detail matters, raise proxy_long_side before you raise the thresholds.
It assumes source and generated are spatially aligned. This is a comparison, not a registration. If the generated crop came back shifted or rescaled - a real thing when you stitch tiles with mismatched geometry - the gate will read that misalignment as invention everywhere and pull the whole frame back to source. The info line's mean alpha is how you spot it: a suspiciously low mean across a detailed image says align your pipeline, not your thresholds.
And it's v25. The pack ships two successors in the same file. DOGMAEvidenceGateV36 adds a novelty veto - a generated edge much stronger than any source edge is treated as invented, with a penalty that scales as source support drops, which is aimed squarely at the classic "model added a bus to an empty street" case. DOGMAEvidenceGateV381 extends that with a broad-change and low-frequency-structure term, plus a hard zero for strong new structure in weak-support regions. Same inputs, same outputs, more aggressive at saying no. Start with this one when you want a light touch; move up the versions when you're fighting invention.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| generated | IMAGE | — | |
| source | IMAGE | — | |
| flat_generated_weight | FLOAT | 0.100–0.8 | — |
| low_threshold | FLOAT | 0.0100–0.2 | — |
| high_threshold | FLOAT | 0.0450.001–0.3 | — |
| proxy_long_side | INT | 25696–512 | — |
| support_grow | INT | 50–16 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| evidence_weight | MASK | — |
| info | STRING | — |