😺NKD Klein Reference Region
Pin one reference to one zone of the canvas
- model
- latent
- mask
- model
- latent
Here's a Klein workflow problem that has no stock solution: you've got a reference image that should only influence part of the canvas. Maybe a product shot that should control just the item on the table, while the rest of the scene takes its cues from the prompt and other references. Without help, Klein spreads every reference across the whole image. NKD Klein Reference Region is the experimental node that confines one reference to one masked zone - the reference's influence is held inside the area you paint, and can be reinforced inside it.
It's part of the pack's newer regional-reference family (with Reference Fit and Reference Control), all marked experimental. On reasonable settings it works cleanly; on strong settings expect a little bleed into neighbors. The author is upfront about it and says so in the README.
How it works
Klein's attention is joint over [txt | canvas | ref_0 | ref_1 …] - every canvas token "sees" a reference through the attention weight from that canvas query to the reference's keys. This node exploits that: it installs an attention patch (set_model_attn1_patch) that adds a per-position bias to the canvas-query × this-reference-key block. Canvas tokens inside your mask keep neutral or boosted attention toward the reference; tokens outside get a strong negative bias so the reference stops influencing them.
Because the mask is area-pooled down onto the model's token grid (from your latent), the whole thing is resolution-independent - repaint your mask at any size and the containment scales with it.
Inputs that matter
- model - from Presampling. The node returns a patched clone of it.
- latent - Presampling's
latentoutput. Used to map your mask onto the token grid; without it the node can't localize and bails out safely. - mask - the zone this reference should fill. White = the reference applies here; black = it's kept out.
- reference_index - which reference to confine.
0= the main reference (ref_0),1= ref_1, in connection order. Usually a secondary reference (1+). - region_weight - how strongly the reference shows up inside the zone. 1 = normal, above 1 reinforces (up to 4), below 1 dilutes even inside. Note the tooltip's warning: pushing this high can make the reference bleed - tighten the zone with
region_hardnessinstead. - outside_suppression - how much the reference is held back outside the zone. 1.0 = it appears only inside; 0.0 = no regional restriction (acts everywhere, like a normal reference).
- region_hardness - crispness of the zone edge. 0 = soft falloff that follows your mask's blur (natural blend, but the reference can halo just outside). 1 = hard binary edge - tightest containment, though the boundary snaps to the token grid and can look slightly stepped.
Outputs are model and latent; the latent passes through so you can chain one node per region/reference, each with its own mask.
The crucial pairing: Reference Fit
A masked region only sees the slice of the reference that overlaps it positionally, because Klein lays every reference over the whole canvas. That's where NKD Klein Reference Fit comes in - it scales the reference to fit your mask's bounding box so the whole reference lands inside the zone. The intended wiring is:
reference image → NKD Klein Reference Fit (with your mask) → Presampling's ref slot
your mask → NKD Klein Reference Region → sampler
Use the same mask in both nodes. Without Fit, you'll get a partial or misaligned crop inside the zone.
Wiring and installing
On the model line between Presampling and your sampler:
NKD Klein Presampling → NKD Klein Reference Region → [your sampler] → NKD Klein Postsampling
Connect Presampling's model and latent in, attach the mask, set the index, run. Install via ComfyUI Manager (search NKD Klein Tools) or:
cd ComfyUI/custom_nodes
git clone https://github.com/Nekodificador/ComfyUI-NKD-Klein-Tools
Restart ComfyUI. No pip dependencies - requirements.txt is empty, so no conflicts to fight. You need a Flux Klein model (4B or 9B plus Qwen3 encoder and VAE) yourself; the pack ships no weights.
Gotchas
- Empty or all-black mask → no-op. The node logs a warning and passes the model through rather than accidentally blocking the reference everywhere.
- Mask without a latent. It can't build the token-grid mapping, so the region is skipped (strength only) - check the console warning.
- Bleed outside the zone. Dial
region_hardnessup toward 1.0 rather than fighting it with the other knobs.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| latent | LATENT | The canvas latent from Presampling — used to map your mask onto the model's token grid. Connect Presampling's latent output here. | |
| mask | MASK | The zone this reference should fill. White = the reference applies here; black = it's kept out. | |
| reference_index | INT | 10–7 | Which reference to confine to the zone. 0 = the main reference (ref_0), 1 = ref_1, … in the order added. Usually a secondary reference (1+). |
| region_weight | FLOAT | 1.000–4 | How strongly the reference shows up INSIDE the zone. 1.0 = normal, above 1 reinforces (up to 4), below 1 dilutes it even inside the zone. Note: pushing this high can make the reference bleed into neighbouring areas — use region_hardness to tighten the zone instead. |
| outside_suppression | FLOAT | 1.000–1 | How much the reference is held back OUTSIDE the zone. 1.0 = it appears only inside the zone; 0.0 = no regional restriction (acts everywhere, like a normal reference). In between fades the restriction. |
| region_hardness | FLOAT | 0.000–1 | Crispness of the zone edge. 0.0 = soft falloff (follows your mask's blur — natural blend, but the reference can halo just outside the zone). 1.0 = hard binary edge (tightest containment; the boundary snaps to the token grid so it may look slightly stepped). Raise this if the reference bleeds into areas you didn't mask. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| model | MODEL | — |
| latent | LATENT | The same latent, passed through — chain it into the next Reference Region to drive several regions. |