Nodes/ComfyUI-QwenImageLayered/QwenImage Layered V2 Brush Context
ComfyUI Node

QwenImage Layered V2 Brush Context

Turn a mask into the brush the V2 pipeline actually understands

By bambom·Created 4 months ago·Updated 4 months ago· 0
QwenImage Layered V2 Brush Context
  • image
  • target_mask
  • remove_mask
  • context_image
invert_targetfalse
invert_removefalse

Here's the whole reason this pack exists. ComfyUI's native Qwen-Image-Layered workflow - UNETLoader → LoraLoaderModelOnly → ModelSamplingAuraFlow → KSampler - loads the V2 LoRA and samples fine, but it has no way to tell the model which element to separate. This node is the missing translator: it takes a ComfyUI MASK (the same kind any mask-making, Grow/Blur, or segmentation node produces) and encodes it into the RGBA context_image that DiffSynth's official V2 pipeline reads.

The encoding is color-coded, and it's the one thing you have to get right:

  • Red channel - target_mask: the region you want extracted.
  • Green channel - remove_mask: the region you explicitly want excluded (optional).
  • Both at once - yellow: the occluded back layer that sits behind your target.

So a single RGBA image can say "pull this, skip that, and here's the bit hiding behind it." That overlap logic is the layered part of Qwen-Image-Layered doing its job - it's what lets the model reason about occlusion instead of just cutting a hole.

Inputs and output

Required: image (used only to size the output context to match), target_mask (the MASK you want extracted), and invert_target (default False) to flip the target mask's polarity. Optional: remove_mask and invert_remove, same idea for the exclusion region.

Output is one context_image (an IMAGE), which you wire into QwenImage Layered V2 Decompose's context_image socket - or into a PreviewImage first, which is genuinely worth doing the first time.

The troubleshooting habit

The README's single most useful warning is about direction: if your Decompose output looks like it dug out the opposite of what you brushed, don't re-prompt, re-invert. Preview the context image before sampling - if your region is showing up in the green channel or is inverted, flip invert_target and you'll save yourself a couple of slow 20B runs.

Keep in mind the softer limitation that runs through this whole pack: the context image is guidance, not a hard mask. The model reads it as a strong hint about what to isolate, and it usually cooperates - but it isn't the pixel-pinning guarantee that a masked inpaint gives you. Check the preview, then trust but verify the output.

Getting the mask in the first place

Nothing here is mask-specific, which is the nice part. Any ComfyUI mask source works: a hand-painted mask on a MaskEditor, an ImageToMask off a selection, a BiRefNet or segmentation pass, or Grow Mask / Blur Mask to soften your brush edge before it becomes context. The reference workflow in the README is exactly that - Load Image → Grow/Blur Mask → target_mask, with an optional second mask lane to remove_mask for green.

One honest note on scope: this is a small prototype pack's node, so the ergonomics are minimal - no preview widget baked in, no fancy brush editor. You bring your own mask tooling. But the thing it does, the native ComfyUI path still can't: giving the layered model a real brush to work with.

CategoryQwenImageLayered/V2

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
target_maskMASK
invert_targetBOOLEANfalse
remove_maskoptMASK
invert_removeoptBOOLEANfalse

Outputs (1)

NameTypeDescription
context_imageIMAGE