Nodes/ComfyUI-Portrait-Maker/FaceShapMatch PM
ComfyUI Node

FaceShapMatch PM

Glue a regenerated face back into the photo without melting the rest

By THtianhao·Created 3 years ago·Updated 2 years ago· 201
FaceShapMatch PM
  • source_image
  • match_image
  • face_box
  • IMAGE

FaceShapMatch PM is the finale node of the EasyPhoto-style pipeline: the thing that stops a face regeneration from wrecking the whole photo. The typical portrait flow regenerates the face region with img2img at low denoise, and the face comes out right - but the edges look bolted on, the background drifts, or something unrelated gets re-imagined along the way. This node fuses the regenerated image into the original using a feathered face mask, so only the face changes and everything around it stays untouched.

How it works

It's a masked paste-back with a real matting step behind it. RetinaFace locates the face, then a 19-class BiSeNet semantic segmentation model (the same face-parsing network EasyPhoto uses, shipped as face_skin.pth) picks out skin, brows, eyes, nose, mouth, and ears. The code runs a morphological close to fill holes, dilates to pull in the surrounding area, then blurs the mask into softness. The output is source_image * mask + match_image * (1 - mask) - the processed face sitting on top of the original photo with feathered edges.

The author's own comment in the source is worth quoting, because it's the whole reason this node exists: "Using I2I generation controlled solely by OpenPose, even with a very small denoise amplitude, still carries the risk of introducing NSFW and global incoherence." In other words, letting the sampler decide everything is how you get a face that's right and a background that isn't - paste-back keeps the unchangeable parts unchangeable.

Inputs and outputs

  • source_image - the original photo.
  • match_image - the regenerated/processed image whose face you want to keep.
  • face_box - the face bounding box. No auto-detection here: wire this from RetinaFace PM or any BOX output.

Output is a single IMAGE at the same resolution as the inputs.

The traps

The face box is required and nothing detects it for you - forget it and the node errors out. Both images must be the same size; if the regenerated pass changed dimensions, normalize them with ImageResizeTarget PM first. And be clear-eyed about what this node can and can't do: it's a deterministic alpha blend, so if the regenerated face has wrong proportions or a weird expression, the mask won't fix it - it just pastes what you gave it, more gently than a hard crop would. First run is also not instant: it loads face_skin.pth plus the ModelScope RetinaFace detector, so expect a delay while models fetch.

Installing it

ComfyUI Manager (search "ComfyUI-Portrait-Maker") or:

cd ComfyUI/custom_nodes
git clone https://github.com/THtianhao/ComfyUI-Portrait-Maker.git

Restart ComfyUI afterward. The pack downloads its model set on first startup with no hash verification - let it run to completion, and if it's interrupted, delete the partial files and retry. Note this pack is a port of EasyPhoto, the A1111 extension that had its popularity wave in late 2023 and has since gone quiet; that lineage means the dependencies are heavy (modelscope, insightface, tensorflow, opencv, diffusers==0.18.2) and Windows users should be on Python 3.11 for the bundled insightface wheel.

Categoryprotrait/model

Inputs (3)

NameTypeDefaultDescription
source_imageIMAGE
match_imageIMAGE
face_boxBOX

Outputs (1)

NameTypeDescription
IMAGEIMAGE