Nodes/ComfyUI-FaceChain/FC ReplaceByMask
ComfyUI Node

FC ReplaceByMask

FC ReplaceByMask — the paste node that respects your mask exactly

By THtianhao·Created 3 years ago·Updated about a year ago· 147
FC ReplaceByMask
  • source_image
  • replace_image
  • mask
  • IMAGE

FC ReplaceByMask is the compositing node you'll wire into the end of just about every FaceChain graph: take two images and a mask, and paste one image inside the mask region over the other. Source image, replacement image, mask in - one blended image out.

It's the "according to the mask" part of the README's one-line description, and it's refreshingly literal. The math is a weighted blend:

result = source * mask + replace * (1 - mask)

Where the mask is 1, you keep the source; where it's 0, you take the replacement. No cleverness, no feathering, no automatic edge smoothing. What you feed in is what you get.

Inputs

  • source_image (IMAGE) - the base image you're pasting onto (the original photo).
  • replace_image (IMAGE) - the content to paste in (a generated face, a swapped region, anything).
  • mask (MASK) - decides where each image wins.

One IMAGE output.

The thing to understand: mask polarity

Because the blend is source * mask + replace * (1 - mask), the mask's white area keeps the source, and the black area is where the replacement shows through. That's the opposite of what most people instinctively expect from a "paste" node - you usually want the mask white where the new content goes. Every node in this pack that produces a mask knows this polarity and produces its masks to match (the outputs of FC FaceDetectCrop and FC FaceSegment work out of the box), but if you're bringing in a mask from elsewhere, check whether you need to invert it first. This single detail causes most of the "my replacement vanished" confusion.

Where it fits

The standard ending: FC FaceSegment's soft_mask (or FC MaskOP output) + a generated face from the sampler as replace_image, pasted over the original as source_image. It's also the manual fallback when FC FaceSegAndReplace's built-in compositing misbehaves - with this node you can see the mask and fix it yourself.

One honest note: there's no edge blur here, so a hard mask leaves a visible seam. Run the mask through FC MaskOP (blur) before this node, or accept the hard edge for fine-cut pastes.

Install

Part of ComfyUI-FaceChain - ComfyUI Manager (search "ComfyUI-FaceChain") or git clone https://github.com/THtianhao/ComfyUI-FaceChain into custom_nodes/, restart. The node itself is pure numpy - instant, no model downloads - though the pack's heavy startup dependency install and first-run ModelScope downloads apply to the pack as a whole.

Categoryfacechain/crop

Inputs (3)

NameTypeDefaultDescription
source_imageIMAGE
replace_imageIMAGE
maskMASK

Outputs (1)

NameTypeDescription
IMAGEIMAGE