Nodes/Enhanced Image Composite Masked/Enhanced Image Composite Masked
ComfyUI Node

Enhanced Image Composite Masked

When the inpainted patch comes back the wrong color, this node fixes it

By darkamenosa·Created 12 months ago·Updated 12 months ago· 6
Enhanced Image Composite Masked
  • destination
  • source
  • mask
  • IMAGE
x0
y0
resize_sourcefalse
blend_modepoisson

This is the node you reach for after the model has done its job. If you're working with an image-space inpainting model - Google Nano Banana, ByteDance Seedream 4, the whole crop-then-merge school of local editing - you generate a patch, and then you have to glue it back onto the original without a visible seam. Stock ComfyUI's ImageCompositeMasked just alpha-composites the pixels, and that's the problem: image-space models often render the patch in colors that don't match the surrounding image. Seedream 4 is the worst offender, consistently brightening whatever it generates. Enhanced Image Composite Masked is the same paste-back step, plus a proper Poisson blend mode that re-colors the patch to match its surroundings while keeping the generated texture.

If you've read the community's inpainting advice at all, you know the golden rule: composite after inpainting, don't let a VAE round-trip degrade the whole frame. This node is exactly that rule in one box, with a color-harmonizer bolted on for the cases where plain compositing leaves a ring around your fix.

How it works

The node has two blend modes, and the blend_mode dropdown defaults to poisson:

  • default - plain alpha/mask compositing. Same behavior as the stock ImageCompositeMasked; fine for Nano Banana, which usually gets colors close enough that nobody notices.
  • poisson - gradient-domain blending from the classic "Poisson Image Editing" paper (Pérez et al., 2003). It keeps the source patch's gradients (textures, edges, details) while forcing the boundary colors to match the destination, so the patch's overall brightness and tint gradually get pulled into line with the original image.

The interesting bit is that the Poisson solver is pure PyTorch - a Jacobi iterative solver running directly on the image tensors, up to 400 iterations with a 1e-4 convergence tolerance, a 4-neighbor Laplacian, and replicate padding at the edges. No OpenCV, no sparse matrices, no feathered-ellipse approximation. It runs on CUDA if you've got it, and it processes batches, so the same node works on video frames. The flip side: Jacobi converges slowly, and 400 iterations per frame on a 4K crop is real compute, so don't expect instant on big patches.

The inputs that matter

  • destination - your original/background image.
  • source - the generated patch you're gluing in.
  • x / y - top-left placement of the patch on the destination (0 to 16384).
  • resize_source - if the source overflows the destination at (x, y), scale it (and the mask) down to fit.
  • blend_mode - default or poisson, discussed above.
  • mask (optional) - the blend region. Don't have one? If the source carries an alpha channel it uses that; if neither, the whole patch gets blended.

Output is a single IMAGE, ready to wire to Save Image or on to the next node.

Installation

Via ComfyUI Manager (search "comfy_inpaint_blend" or "Enhanced Image Composite Masked"), or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/darkamenosa/comfy_inpaint_blend.git
pip install -r comfy_inpaint_blend/requirements.txt

Then restart ComfyUI. The node shows up under image/inpainting. One relief: requirements.txt lists opencv-python, but the shipped code never imports it - the whole thing is torch + numpy, so the "heavy dependency" is a no-op in practice.

Where people get burned

  • Mask size mismatch. If your mask isn't the same dimensions as the source, the node raises an error unless resize_source is on. Match your crop and mask, or flip that switch.
  • Soft masks get binarized. Poisson mode thresholds the mask at 0.5 to define the strict solve region, so don't rely on feathering to do the blending - the solver's boundary condition does that work, not your mask's soft edges.
  • Poisson fixes color, not content. It harmonizes brightness and tint so the patch doesn't look pasted on. It will not rescue a patch that generated the wrong object or a hand with six fingers - the structure is whatever the model gave you. Think of it as the final color-grade, not a magic seam remover.
  • It's a companion, not a full inpainting suite. The author (same person behind the well-received comfy_nanobanana custom node) targets the image-space workflow: crop the masked region, generate with Nano Banana or Seedream 4, then merge back. If you're on a latent-space stack, the stock ImageCompositeMasked or the Inpaint Crop-and-Stitch pattern still covers you - you're paying for the Poisson mode here, and you only want it when color mismatch is your actual problem.
Categoryimage/inpainting

Inputs (7)

NameTypeDefaultDescription
destinationIMAGE
sourceIMAGE
xINT00–16384
yINT00–16384
resize_sourceBOOLEANfalse
blend_modeCOMBOpoisson2 options: default, poisson
maskoptMASK

Outputs (1)

NameTypeDescription
IMAGEIMAGE