Nodes/Eden.art nodesuite/Eden_Face_Crop
ComfyUI Node Runs on cloud

Eden_Face_Crop

Crop the main face out of a mask, cleanly

By edenartlabΒ·Created 3 years agoΒ·Updated 6 months agoΒ· 119
Eden_Face_Crop
  • image
  • face_mask
  • cropped_face
  • crop_x
  • crop_y
  • crop_width
  • crop_height
  • crop_mask
  • custom_mask
β—„padding_factor1.2β–Ί
β—„threshold0.50β–Ί
β—„min_face_ratio0.010β–Ί

Face work in ComfyUI is a two-step dance: first find the face, then do something useful with it. Eden_FaceToMask handles step one (detect faces, emit a mask). Eden_Face_Crop handles step two: it takes an image and a face mask, figures out where the main face actually is, crops it out with proper padding, and hands you back the crop plus the exact coordinates and a reconstruction mask. It's the node that turns "I have a face mask" into "I have a cropped, correctly-bounded face I can inpaint, upscale, or swap."

It's from Eden.art's face toolkit, and it pairs with FaceToMask so neatly that you should think of them as one unit.

How it works

The crop logic runs on the mask, not the image, which is the right way to do it. Given the face_mask, it thresholds it (any pixel above threshold, default 0.5), finds connected components using SciPy's label function, and picks the main face region - the largest valid component, filtered by min_face_ratio so tiny specks (and noise) don't get treated as faces. It then expands that bounding box by padding_factor (default 1.2 = 20% extra room around the face), clamps to image bounds, and crops.

That's why it's robust to messier inputs: it doesn't just take the brightest spot of the mask, it finds the dominant connected region, which is what survives when a mask has bleed or multiple faces in frame.

Inputs and outputs

  • image - the full frame.
  • face_mask - a MASK from FaceToMask (or any hard/soft face mask).
  • padding_factor (default 1.2) - how much room around the face. Crank to 1.5–2.0 when you want context (ears, hair, neck) included, drop toward 1.0 for a tight crop.
  • threshold (default 0.5) - mask binarization level.
  • min_face_ratio (default 0.01) - minimum face size as a fraction of the image dimension, squared; below this, regions are ignored as noise.

Outputs (this is where it pays for itself):

  • cropped_face - the cropped IMAGE.
  • crop_x, crop_y, crop_width, crop_height - the crop geometry.
  • crop_mask - the mask cropped to the same region (matches the crop exactly).
  • custom_mask - a mask of the crop region placed back in the original frame coordinates, so you can composite the result home.

The workflow it enables

The KB's identity-preservation essay is the backdrop here: face detection is the cheap, license-friendly part (MediaPipe), and the crop is what feeds everything else. The classic chain is LoadImage β†’ Eden_FaceToMask β†’ Eden_Face_Crop β†’ upscale or inpaint the cropped face β†’ composite back using crop coords / custom_mask. Because you get the geometry out as plain ints, you can also log or re-crop deterministically. And per the KB's inpainting rules, if you're repairing the face, crop tight-ish, fix at high resolution (the "only-masked detail at full resolution" advantage), then paste back - this node's coordinate outputs are exactly what that paste-back needs.

Installing

Part of edenartlab/eden_comfy_pipelines (Eden.art nodesuite), installed once for everything:

cd ComfyUI/custom_nodes
git clone https://github.com/edenartlab/eden_comfy_pipelines.git
cd eden_comfy_pipelines
pip install -r requirements.txt

Or ComfyUI Manager β†’ search "Eden". Note it uses SciPy's ndimage for connected components - the pack's requirements include scikit-learn/scikit-image/opencv, so pip install -r requirements.txt should cover it.

Gotchas

It needs a real face mask - feed it an empty or garbage mask and it returns a no-op rather than inventing a face, so check your FaceToMask output first. Watch padding_factor at the extremes: 1.0 clips right at the bounding box (ears often cut), and very large values can push the box off-frame, though it clamps. And remember this is a mask-based crop, not a fresh detector - if you want it to find a face from the image alone, run it on Eden_FaceToMask's output, not directly on a raw image.

CategoryEden 🌱/face

Inputs (5)

NameTypeDefaultDescription
imageIMAGEβ€”
face_maskMASKβ€”
padding_factorFLOAT1.20.1–10β€”
thresholdFLOAT0.500–1β€”
min_face_ratioFLOAT0.0100.001–1β€”

Outputs (7)

NameTypeDescription
cropped_faceIMAGEβ€”
crop_xINTβ€”
crop_yINTβ€”
crop_widthINTβ€”
crop_heightINTβ€”
crop_maskMASKβ€”
custom_maskMASKβ€”