Nodes/comfyui-fvmtools/K2 Edit Latent
ComfyUI Node

K2 Edit Latent

Regional inpainting on Krea 2 without touching the rest of the frame

By ping1979ping·Created 6 months ago·Updated about a month ago· 0
K2 Edit Latent
  • image
  • vae
  • regions
  • plan
  • mask
  • latent
  • edit_mask
  • source
  • info
latent_feather64
grow_px0
edit_entire_imagefalse

K2 Edit Latent is the regional-editing front end of the K2 Lab suite in comfyui-FVMtools: it encodes a source image and builds the denoise mask so that only your selected region boxes get re-denoised, while everything else keeps its original latent. It's mask-based inpainting built on the Krea 2 regional system - change the red dress, leave the rest of the photograph alone.

The reason this matters specifically on Krea 2 is that whole-frame edit models are terrible at leaving things alone. The KB's inpainting essay makes the case: instruction editors drift pixels they were never asked to touch, and the drift compounds across a chain of edits. Masked inpainting is the one approach that gives you bit-identical unmasked pixels. This node gives you that on Krea 2, with the box-based UI you're already using for generation.

The inputs that matter

  • image and vae - the source and the VAE to encode it with.
  • latent_feather - the transition collar used during denoising (default 64 px). It lets the model blend structure around the box instead of meeting a hard latent boundary. This is the seam-prevention dial.
  • grow_px - expand every edit box before masking.
  • edit_entire_image - ignores the boxes and edits everything. Only for intentional whole-scene changes; you don't want this on by accident.

Optional regions (the edit boxes), plan (reuse the region layout of a compiled plan), or an explicit mask - and mask overrides regions/plan.

Outputs: latent (feed to the sampler), edit_mask (the mask that tells the sampler what to re-denoise), source, and info.

The 3D VAE trap - this node handles it for you

Krea 2 shares its autoencoder with Qwen-Image, and that's a 3D VAE: encode() returns [B, C, 1, H, W] with a time axis. Without stripping that axis, every img2img path spits out color noise - including ComfyUI's own VAEEncode → KSampler chain, which is a genuinely nasty thing to debug. K2 Edit Latent normalizes to 4D internally. If you've seen that "colorful static from img2img" bug on Krea 2 and assumed the model was broken, this is the fix wearing a node's costume.

The workflow

IMAGE → K2 Edit Latent → K2 Regional Sampler → VAE Decode → K2 Edit Composite → Save

Start with low denoise on the sampler, 64 px latent feather, and the composite feather at 48 on the other side. If you see a seam, the author's advice is blunt: widen the feather or enlarge the box rather than raising denoise. Also worth remembering from the K2_LAB doc: the measured edit locality was 234× stronger inside the edit box than outside - but that's at the right denoise, and pushing denoise up is how you erase that margin.

Install

Same as the whole pack:

cd ComfyUI/custom_nodes
git clone https://github.com/ping1979ping/comfyui-FVMtools

Restart ComfyUI, find it under FVM Tools/K2. No extra Python dependencies. The pixel-level protection after sampling is done by K2 Edit Composite - latent editing alone can't keep unmasked pixels bit-identical, so wire them together.

CategoryFVM Tools/K2

Inputs (8)

NameTypeDefaultDescription
imageIMAGESource image to edit.
vaeVAEVAE used to encode the source.
latent_featherINT640–512Soft collar around each edit box in pixels.
grow_pxINT0-256–512Expand every edit box before masking.
edit_entire_imageBOOLEANfalseIgnores the boxes and edits everything. Only for intentional whole-scene changes.
regionsoptK2_REGIONEdit boxes. Alternatively connect a plan or an explicit mask.
planoptK2_PLANUses the region layout of a compiled plan.
maskoptMASKExplicit mask; overrides regions/plan.

Outputs (4)

NameTypeDescription
latentLATENT
edit_maskMASK
sourceIMAGE
infoSTRING