Nodes/NKD Klein Tools/😺NKD Klein Postsampling
ComfyUI Node

😺NKD Klein Postsampling

The node that puts your Klein edit back where it belongs

By Nekodificador·Created 4 months ago·Updated 11 days ago· 80
😺NKD Klein Postsampling
  • image
  • bundle
  • image
  • debug_difference
â—„uncrop_feather10â–º
â—„match_original_colors0.00â–º
â—„seamless_edgesfalseâ–º
â—„auto_detect_edit_regionfalseâ–º
â—„edge_softness2.00â–º
â—„region_padding0.0â–º
â—„fill_inner_gapsfalseâ–º
â—„remove_specks0.10â–º
â—„extend_to_borderstrueâ–º
â—„transparent_backgroundfalseâ–º

Klein is a great editor, but it has a tell: it likes to rewrite more than you asked. Point it at a photo, ask for one change, and the whole canvas comes back close but not identical - a slightly warm white balance here, a recomposed background there. Fine for a one-off, miserable when you're chaining five edits and the drift compounds. NKD Klein Postsampling is the node that stops that from being a problem: it composites your sampler's output back over the original so the parts you didn't touch stay pixel-for-pixel untouched.

It's the other half of the NKD Klein Tools pair. Presampling prepares the job, your sampler generates, and this node assembles the final image - undoing the cropping, re-applying the masks, and blending the regenerated zone back into the scene.

How it works

Postsampling takes two things: the image coming out of your sampler (after a VAE Decode), and the bundle that Presampling handed you. That bundle carries everything the node needs to reverse the preprocessing - crop boxes, processed masks, the original image, and which mode you were in. The node picks the right path automatically:

  • Detailing crop → the generated patch is pasted back onto the original at its native full resolution, feathered by Uncrop Feather.
  • Masked inpainting → alpha-blends the sampled area over the original, so the unmasked pixels stay bit-identical. That's the one thing masked editing still owns outright (the KB's inpainting doc makes the case: no edit model offers unchanged pixels; only a composite does).
  • Plain img2img → passes the image through, unless you switch on the auto-detect path below.

The three fixes that make edits look right

  • Match Original Colors (0–1) - Klein's reproducible warm color shift on edits is the best-known complaint about the model, and this is the targeted cure. It pulls the regenerated area's colors and lighting back toward the original, reading statistics only from the unchanged background so the edit itself keeps the colors it was supposed to have.
  • Seamless Edges - turns on Poisson blending to mathematically erase any remaining color/lighting seam at the zone boundary. Reach for it on dramatic relighting or strong style changes; it's heavier and can smear textured edges, which is why it's off by default.
  • Auto-Detect Edit Region - for img2img without a mask. It figures out which pixels actually changed between your input and the generated image, and composites only that region back. Chain several edits and the untouched areas never drift. Its controls - Edge Softness, Region Padding, Fill Inner Gaps, Extend To Borders - tune the detected region before blending, all expressed as a percentage of the image diagonal so they behave the same at any resolution.

There's also a debug_difference output: a view that exaggerates what changed. Wire it to a Preview Image to eyeball whether the detected region (or the seam) looks clean - genuinely useful the first few times you set the auto-detect knobs.

The catch worth knowing

Seamless Edges and Auto-Detect Edit Region need OpenCV (cv2). The node checks for it at runtime; if it's missing it logs a warning and falls back to a basic blend, which silently degrades quality. ComfyUI ships with OpenCV in most installs, but if you're on a stripped environment and those features aren't behaving, pip install opencv-python into your ComfyUI environment. Nothing else in the pack has external dependencies - requirements.txt is empty.

Installing

Search NKD Klein Tools in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/Nekodificador/ComfyUI-NKD-Klein-Tools

Restart ComfyUI after either. You'll need a Flux Klein model loaded (4B or 9B with its Qwen3 encoder and VAE) - the pack provides no weights.

Common issues

  • Not connected to the bundle. Postsampling without the bundle from Presampling has nothing to composite against; keep that wire intact from the start of the chain.
  • Auto-detect does nothing. It only runs for img2img (an input image but no mask). If you've got a mask connected, masked inpainting takes over and the toggle is ignored - by design.
  • Detected region edges look off. That's what Region Padding (grow or shrink the detected zone) and Edge Softness are for; check the debug_difference view first and tune from there.
Category😺NKD Nodes/Klein

Inputs (12)

NameTypeDefaultDescription
imageIMAGEThe image coming out of your sampler chain.
bundleNKD_KLEIN_BUNDLEComes from NKD Klein Presampling. Carries everything this node needs to assemble the final image.
uncrop_featherINT100–256How softly the regenerated zone blends back into the original image. Higher values give a more gradual transition; lower values keep the edge crisp.
match_original_colorsFLOAT0.000–1Pulls the regenerated area's colors and lighting back toward the original image. The model often shifts the overall white balance or saturation slightly — this corrects that drift so the composite looks like it belongs to the same scene. 0 leaves the colors as the model produced them; 1 fully matches them to the original. Statistics are read only from the unchanged background, so the edit itself keeps the colors it was supposed to have.
seamless_edgesBOOLEANfalseUses Poisson blending to mathematically erase any remaining color or lighting seam at the edge of the regenerated zone. Turn this on when the boundary is still visible after color matching — usually on dramatic relighting or strong style changes. Heavier than a normal blend and can introduce smearing on textured edges, so leave it off by default.
auto_detect_edit_regionBOOLEANfalseWhen you run an edit without giving a mask, this turns on automatic detection of what actually changed between your input and the generated image, and composites only that region back. Keeps the unchanged parts of the original pixel-perfect across multiple iterative edits, instead of letting the model rewrite the whole canvas every time. Only used when there is an input image but no mask — ignored otherwise.
edge_softnessFLOAT2.000–10How softly the auto-detected region fades into the original. Expressed as a percentage of the image diagonal, so the same value looks the same at any resolution. Higher values give a wider, gentler transition (good for skin, fabric, hair); lower values keep the edge tight (good for geometric edits). Only used when Auto-Detect Edit Region is on.
region_paddingFLOAT0.0-3–3Grows or shrinks the auto-detected region before blending. Positive values expand outward — handy when the detection falls just short of the true edges. Negative values pull the region inward — handy when it bleeds into background that should stay untouched. Expressed as a percentage of the image diagonal. Only used when Auto-Detect Edit Region is on.
fill_inner_gapsBOOLEANfalseFills small holes inside the auto-detected region. When the edit changed an object's color or texture but not its interior contrast, detection can leave little voids in the middle. Turn this on to seal them so the whole object gets composited cleanly. Only used when Auto-Detect Edit Region is on.
remove_specksFLOAT0.100–5Cleans up the little floating scraps the detection leaves scattered around the image — grain and noise that changed just enough to be flagged. Any detected patch smaller than this percentage of the image area gets dropped. Raise it if specks still get through, lower it if a genuinely small edit (an earring, a button) is being erased. 0 turns it off. Only used when Auto-Detect Edit Region is on.
extend_to_bordersBOOLEANtrueExtrapolates the auto-detected region into any border void the alignment step leaves behind. Without this, a thin frame of the original can peek through around the edge of the regenerated zone. Leave on unless you see mirrored artifacts at the image border. Only used when Auto-Detect Edit Region is on.
transparent_backgroundBOOLEANfalseOutputs the image with an alpha channel: only the regenerated area stays opaque and everything else becomes transparent — ready to save as a PNG cutout or composite elsewhere. Needs a mask (or Auto-Detect Edit Region) to know what the edited area is; without one the image comes out normal.

Outputs (2)

NameTypeDescription
imageIMAGE—
debug_differenceIMAGEA debug view that exaggerates the difference between the result and the original. Connect it to a Preview Image to spot where things changed and check the edges look clean. Not needed for normal use.