Nodes/Face-Aligned Center/Face-Aligned Center
ComfyUI Node

Face-Aligned Center

Same character, same size, every angle — no face detector required

By serhiiyashyn-sf·Created 4 months ago·Updated 4 months ago· 0
Face-Aligned Center
  • images
  • mask
  • images
  • masks
  • info
canvas_size928
face_fill0.12
face_y0.30

If you've ever tried to turn a multi-angle character sheet into a clean training set, you know the pain: the front view fills the frame, the side view shrinks, the back view drifts off to one side, and by the time you bucket them into a LoRA dataset they look like eight different characters. Face-Aligned Center is the batch-aware fix for exactly that. Feed it a character sheet - typically the 8-angle front / three-quarter / side / back lineup - and every frame comes out with the head at the same size and the same canvas position, including the back view that has no face in it at all.

That last part is the trick, and it's why the node is more interesting than its zero-hype profile suggests. It never calls a face detector - the "silhouette fallback" the README mentions is really the main event.

How it works

The pipeline is three passes, and reading them tells you what it's actually optimizing for.

Pass 1 - background and foreground. It samples the median color along the image border (a full frame strip, not just four corners, so a character touching the edge doesn't skew it), then builds a foreground mask with a max-channel difference threshold. The author notes this generalizes the classic min(RGB) < 245 rule for white backgrounds to any uniform fill - white, green-screen, black all work.

Pass 2 - silhouette analysis. Per image it trims thin rows off the top and bottom (so a spear tip doesn't inflate body height), then finds the head's horizontal center using the midpoints of each row's longest contiguous run. That run-length trick is what makes it robust to sceptres and swords jutting sideways - the weapon is a separate thin run, so it loses to the main body run when you take the median.

Pass 3 - one scale for the whole batch. Here's the batch-aware part: it derives a target body height from your face_fill and an assumed chibi-like face-to-body ratio (0.21), then scales every image by the same factor from the batch's median body height. One scale for all eight angles means they all end up at the same physical size - the whole point. Then it translates each image's head center to the target canvas position and pads with the background color it detected on that image, so a green-screen sheet stays on clean green.

The inputs that matter

  • face_fill (default 0.12) - the zoom knob. Face height as a fraction of the canvas. Lower = more empty space around the character, higher = tighter crop. The tooltip makes the workflow-relevant point: the same value across every call gives the same face size for every character sheet, which is exactly what you want when building a consistent dataset.
  • face_y (default 0.30) - vertical position of the face center, 0 = top, 1 = bottom. 0.30 parks the face in the upper third.
  • canvas_size (default 928) - square output in pixels.
  • mask (optional) - a pre-computed foreground mask. It overrides the auto background detection entirely.

Outputs are images, masks (the scaled/translated foreground mask, handy for downstream compositing or validation), and a STRING info diagnostic printing the batch scale plus each image's detected head coordinates. When something's misaligned, that info output is the first place to look.

Installing

Via ComfyUI Manager (search "Face-Aligned Center"), or the manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/serhiiyashyn-sf/comfyui-face-aligned-center
cd comfyui-face-aligned-center
pip install -r requirements.txt

Then restart ComfyUI. The node lives under the FaceAlignedCenter category. Dependencies are numpy, torch, Pillow, opencv-python and ultralytics - the last is the heavyweight, and it's really there for the sibling Anime Face Detect node, not this one. No models to download; it's all CPU math on border colors and silhouette.

Where people get burned

The one real requirement: the background has to be a uniform fill. Busy, patterned, or photo backgrounds defeat the border-color detection and your foreground mask will be garbage. If your sources aren't on a clean backdrop, feed in your own mask rather than hoping. Also worth knowing: it trusts RGBA alpha only if the alpha actually carries transparency - many ComfyUI pipelines pass 4-channel tensors with alpha=1.0 everywhere, and the code correctly ignores that and falls back to color detection.

It's a young, single-author pack (v1.2.1, MIT) - no decade of community troubleshooting to lean on. But the code is short and readable, the defaults are sane, and for its one job - turning a character sheet into a consistent, evenly-framed batch - it's genuinely the tool I'd reach for. Wire it into a LoRA training prep graph ahead of the dataset save and the framing inconsistency just stops being a variable.

CategoryFaceAlignedCenter

Inputs (5)

NameTypeDefaultDescription
imagesIMAGE
canvas_sizeINT92864–8192Square output size (pixels).
face_fillFLOAT0.120.02–0.9Zoom knob. Target face height as a fraction of the canvas. LOWER = zoom out (smaller character, more empty space). HIGHER = zoom in. Same value across every call = same face size for every character sheet.
face_yFLOAT0.300–1Vertical position of the face center on the canvas (0=top, 1=bottom). 0.30 puts the face in the upper-third.
maskoptMASKOptional foreground mask; overrides BG-color auto detection.

Outputs (3)

NameTypeDescription
imagesIMAGE
masksMASK
infoSTRING