Nodes/Image Misc/Face Composite
ComfyUI Node

Face Composite

Put the reanimated face back where it belongs

By set-soft·Created about a year ago·Updated 8 months ago· 2
Face Composite
  • animated
  • reference
  • bboxes
  • images

This is the "put it back" node for face animation workflows. The pattern goes like this: you've got one reference image with a face in it, you crop that face out, run it through AnimateDiff or an SVD-style model to get a batch of animated frames, and now you have a pile of loose animated faces that need to go back onto the original image to become a proper animation. Face Composite is the paste step - it takes the animated face batch and the reference image(s), and stitches each face onto its reference at the given coordinates.

The interesting part is the batch math. The node handles an M-to-N relationship: M reference images, and for each one, N animated frames. You feed in all M×N animated faces plus the M references plus M bounding boxes, and it figures out that reference #0 owns frames 0..N-1, reference #1 owns the next N, and so on. That's the shape a real face-animation workflow produces, and it's what makes this more than a glorified paste.

How it works

For each reference image it converts the tensor to Pillow, then for each of that reference's animated frames it resizes the small face crop to the bounding box dimensions with Lanczos resampling and pastes it onto a fresh copy of the reference. Copies matter: each output frame gets its own untouched base, so no frame pollutes the next. Output is a single stacked batch of M×N full-size images.

The inputs that matter

  • animated - the batch of M×N cropped/processed faces.
  • reference - the M original context images the faces came from.
  • bboxes - M bounding boxes as (x, y, w, h) tuples, one per reference. This is where the workflow glue matters: the boxes come from whatever face-detection node you used to extract the crops (the BBOX type, so it plugs into nodes that speak that format).

The bounding box does double duty - it's both the position to paste at and the size to scale the animated face to, so the face crops don't need to match the bbox resolution beforehand.

Installing it

It's part of Image Misc:

cd ComfyUI/custom_nodes
git clone https://github.com/set-soft/ComfyUI-ImageMisc
cd ComfyUI-ImageMisc && pip install -r requirements.txt

or via ComfyUI Manager ("Image Misc"), then restart. Under image/manipulation.

Common issues

The validation is strict and the errors tell you exactly what's wrong, which is a gift: the reference batch must equal the bbox count, and the animated batch must be a multiple of the reference count. Get those mismatched and it raises instead of silently producing garbage - good behavior. Two real gotchas: this is a hard rectangular paste with no blending, so if the face edges don't line up with the crop you'll see a seam (mask-based compositing is the fix, and that's what the pack's AFFCE nodes are for); and the bbox convention is (x, y, w, h) - if your detection node hands you (x1, y1, x2, y2) corners, convert before wiring it up. There's also a frame-by-frame sibling that uses a single static bbox for video sequences, which you probably want instead if your references are a video rather than stills.

Categoryimage/manipulation

Inputs (3)

NameTypeDefaultDescription
animatedIMAGE
referenceIMAGE
bboxesBBOX

Outputs (1)

NameTypeDescription
imagesIMAGE