π₯π Apply TKG Noise (SD/SDXL)
Get a clean green screen out of Stable Diffusion without retraining
- model
- MODEL
The one trick it exists for
Try prompting Stable Diffusion for "person on a green background" and you'll get a mottled, gradient-y backdrop that no chroma keyer will ever swallow. The model treats background color as a vibe, not a flat swatch. Apply TKG Noise (SD/SDXL) fixes that the sneaky way: it doesn't touch your prompt, your weights, or the sampler settings. It just nudges the initial noise so the model paints a uniform, keyable background behind your subject. That's the whole point of TKG-DM, a research paper (arXiv 2411.15580) that this pack ports into ComfyUI. You get clean green-screen output for compositing - video, product shots, whatever you plan to key - with zero training and zero model downloads.
The niche is real but specific. If you're going to key this background out later, this is the cleanest path on SD/SDXL, beating both segmentation-based extraction (you're reconstructing edges someone already drew) and the LayerDiffusion approach (great when it works, abandoned, fiddly). It's also worth saying the "SDXL" in the name is doing real work: this only runs on the 4-latent-channel SD/SDXL family. Flux has 16 channels and will hard-fail here.
How it works
Despite being filed under latent, this is a model patcher, not a latent node. You feed it the MODEL from your checkpoint, and it returns a clone of that model with a wrapper on the sampler's first step. At that first denoise step, it rewrites the noise: each of the 4 latent channels gets its mean shifted toward a sign that biases the output toward your chroma color, and a gaussian mask centered on the image keeps the middle - your subject - close to untouched. Mean-shifted noise, decoded, reads as a flat uniform background. Clever part: because it only edits noise, it's training-free, and it costs almost nothing per render.
The inputs that matter
- color - pick from 8 presets borrowed from the paper's Figure 28:
green(default),cyan,magenta,purple,black,orange,white,yellow. Each is a real recipe for biasing the 4 latent channels. - shift (0.11) - how hard the background is pushed toward the color. Crank it up for a flatter, more saturated backdrop; back it off if your subject starts taking on the tint.
- grid_factor (8) - resolution the protective gaussian mask is computed at before upscaling. Leave it at 8; it's the "idk why it's 8" knob, per the author's own comment in the source.
Output is a single MODEL - the tooltip says "output latents," which is a lie by omission; it's a patched model. Wire it into the KSampler's model slot in place of the raw checkpoint model.
Install
The README is refreshingly minimal (read: it has almost nothing in it), but the pack is dependency-free - pyproject.toml lists zero Python deps, so there are no model files to fetch and nothing to break. Two ways:
- ComfyUI Manager β search "tkg" or "tkg-chroma-key" β install, restart.
- Manual:
cd ComfyUI/custom_nodes && git clone https://github.com/p1atdev/comfyui-tkg-chroma-key, restart ComfyUI.
It needs Python β₯ 3.11 and a reasonably recent ComfyUI, because the code relies on comfy.patcher_extension - old installs will throw an import error. Drag the examples/TKG-Chroma-Key-Simple.json (or its PNG) into ComfyUI to load a working workflow; it ships pre-wired with an SDXL checkpoint (Animagine XL Zero).
Troubleshooting
- Wired the output into a LATENT input? Stop. It's a MODEL. Model β KSampler's model slot.
- Flux? No. The 4-element color recipes assert against the latent channel count; Flux's 16 channels trips it immediately.
- Background looks tinted but not flat - raise
shift, and/or add "flat solid color background" to your prompt so the model isn't fighting you. - Green spill on the subject - the classic. Drop
shift, try a different preset color, or key it generously in post.
Real talk: this pack has essentially zero community footprint - it's an academic port, and the author (p1atdev, who also made the LECO concept-slider LoRA tool) hasn't polished the README much. But for the one job it does - flat keyable backgrounds without retraining - it works, and there isn't much else that does it without fine-tuning.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | β | |
| color | COMBO | green | 8 options: green, cyan, magenta, purple, black, orange, +2 |
| shift | FLOAT | 0.110β1 | β |
| grid_factor | INT | 81β16 | β |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | Output latents with TKG noise applied |