Nodes/ComfyUI-RMBG/Reference Latent Mask (RMBG) 🖼️🎭
ComfyUI Node Runs on cloud

Reference Latent Mask (RMBG) 🖼️🎭

Masked region conditioning for Flux Kontext

By 1038lab·Created 2 years ago·Updated 8 days ago· 2,051
Reference Latent Mask (RMBG) 🖼️🎭
  • conditioning
  • latent
  • mask
  • CONDITIONING
  • LATENT
  • MASK
expand5
blur3.0
mask_onlytrue

This one's for the Flux Kontext crowd. Kontext edits an image from a reference plus an instruction, but by default it takes the whole reference into context and can drift on the parts you wanted left alone. Reference Latent Mask lets you say "condition on this reference, but only care about this masked region" - precise, localized editing instead of whole-image roulette.

It's the pack's most specialized node, and if you're not doing Kontext-style reference editing you can skip it entirely. If you are, it's the piece that turns Kontext from "regenerate everything and hope" into something closer to targeted inpainting, where the mask actually scopes what the model attends to.

How it works

Flux Kontext consumes reference images in-context rather than through adapter embeddings - that's the architectural trick that makes it good at consistency. This node hooks into that. It takes your conditioning, a reference latent, and a mask, and stitches the masked region of the reference into the conditioning as a spatial hint. The model then knows where the reference matters. Under the hood it's the same idea as ComfyUI's native ReferenceLatent conditioning, with mask scoping and edge cleanup bolted on.

The inputs and outputs that matter

  • conditioning - your text/CLIP conditioning coming into the node. Gets augmented and passed through.
  • latent - the reference latent (your encoded reference image).
  • mask - the region you care about. This is what makes it a masked reference: everything outside gets less weight.
  • expand (-64 to 64, default 5) - grow or shrink the mask before it's applied. A small positive expand avoids hard seams right at the mask edge; go negative to tighten.
  • blur (default 3) - softens the mask edge so the conditioning transitions smoothly instead of cutting off abruptly. This is your anti-halo dial.
  • mask_only (default on) - restrict the effect to the masked area. Turn it off to let the reference inform the whole latent while still weighting the mask.

Outputs are CONDITIONING, LATENT, and MASK - pass the conditioning and latent straight into your Kontext sampler chain; the mask output is the processed (expanded/blurred) version for reuse downstream.

How to install it

  • ComfyUI Manager: search Comfyui-RMBG, install, restart.
  • Manual: cd ComfyUI/custom_nodes && git clone https://github.com/1038lab/ComfyUI-RMBG, then pip install -r requirements.txt, and restart.

No model download for this node itself - but it's useless without a Flux Kontext model loaded in the rest of your graph, and Kontext is a heavy download in its own right.

Common issues

The usual failure is a visible seam or halo around the edited region - that's blur set too low or expand set wrong. Nudge blur up a couple of points and give expand a small positive value so the transition has room to breathe. The other thing to internalize: this node does nothing on its own. It's a conditioning helper for a Kontext pipeline, so if you've wired it into a plain SDXL or Flux-dev graph and nothing happens, that's expected - the reference-latent mechanism only means something to a model that consumes references in-context.

Category🧪AILab/🎭Inpaint

Inputs (6)

NameTypeDefaultDescription
conditioningCONDITIONINGBase conditioning input for inpainting task
latentLATENTEncoded latent from VAE
maskMASKArea to inpaint (white regions)
expandINT5-64–64Grow mask (+) or shrink mask (-)
blurFLOAT3.00–64Soften mask edges
mask_onlyBOOLEANtrueOnly generate content in masked area

Outputs (3)

NameTypeDescription
CONDITIONINGCONDITIONING
LATENTLATENT
MASKMASK