Nodes/Remade_nodes/Batch Image Blend by Mask
ComfyUI Node

Batch Image Blend by Mask

The mask-based paste-back node with a no-op hiding in its tail

By Pheat-AI·Created 2 years ago·Updated 2 years ago· 5
Batch Image Blend by Mask
  • gen_images
  • segmented_image
  • segmented_image_mask
  • IMAGE

Here's the inpainting-family node that ties the pack together. Batch Image Blend by Mask takes your batch of generated candidates (gen_images), a segmented_image (usually the original photo you started from), and a segmented_image_mask, and pastes the segmented image back in wherever the mask says - over every frame in the batch, in one pass.

Think of it as the "restore the untouched parts" step. You inpainted a region of a photo, got a batch of variations, and now you want each result to keep the original pixels everywhere outside the edited area. That's this node's whole personality: generated content inside the mask, original pixels outside, done.

How it works

The mechanism is two PIL Image.composite calls and a bit of dead code. The mask (passed in as an IMAGE, not a MASK type) is converted to grayscale and inverted. Then Image.composite(gen_image, segmented_image, inverted_mask) is called, which picks the generated image where the mask is white and the segmented image where it's black. So: where your original mask was white, you get the original back. The second composite builds an all-black mask and is effectively a no-op that just returns the first result - the author's leftover scaffolding. The output is identical to what the first composite produced, so don't go hunting for an extra blend effect; there isn't one.

The mask is resized to each generated frame's size, which is the one piece of flexibility here.

Inputs and outputs

  • gen_images (IMAGE) - the batch of candidates.
  • segmented_image (IMAGE) - what gets pasted back in, typically the original.
  • segmented_image_mask (IMAGE) - where the original returns. White mask = original pixels.
  • Output: IMAGE, batch of the same length as gen_images.

The mask-semantics gotcha is the thing that bites: because the node inverts internally, a white region in your mask means "show the original here," which is the reverse of the inpainting convention where white means "regenerate here." If your results come out with the original stamped over your edits, you've got the mask polarity backwards - flip it.

Things to know

  • The mask input is an IMAGE. If you have a proper ComfyUI MASK tensor from a segmenter, you'll need to convert it to an image before this node (a common stop for people used to MASK-typed nodes).
  • Sizes: mask gets resized to frame size; the segmented image does not, so keep it at the same dimensions as the batch or you'll get PIL size errors.
  • It loops the batch without checking that the segmented image matches - mismatches fail per-frame, mid-run.

Installing it

It ships in Remade_nodes, installable once for the whole pack:

cd ComfyUI/custom_nodes
git clone https://github.com/Pheat-AI/Remade_nodes

Restart ComfyUI, or use ComfyUI Manager and search Remade_nodes. No models, no README, requirements.txt lists only numpy (and the pack's color-blend node imports OpenCV, so if the whole pack fails to load, pip install opencv-python).

One input batch, one mask, and every candidate comes back with the untouched original pixels restored exactly where you wanted them. Just mind which color means what.

CategoryREMADE/Image

Inputs (3)

NameTypeDefaultDescription
gen_imagesIMAGE
segmented_imageIMAGE
segmented_image_maskIMAGE

Outputs (1)

NameTypeDescription
IMAGEIMAGE