Nodes/Region Edit Toolkit/图像分区 · 人脸上下文裁块
ComfyUI Node

图像分区 · 人脸上下文裁块

The face crop that keeps the shoulders, never upscales, and stops at 1024

By Liu-Bot24·Created 2 months ago·Updated about a month ago· 1
图像分区 · 人脸上下文裁块
  • image
  • selection
  • face_context_crop
  • report_json
crop_size1024

Every face-edit workflow needs the same thing before anything else: a square crop of the face with enough around it that the edit model doesn't reinvent the person's hair, ears, and neck from context-free pixels. RegionEditFaceContextCrop is that step in the Region Edit Toolkit, and it makes two decisions that most naive square-crop nodes get wrong.

First, crop_size is a ceiling, not a target. If your subject is a distant face in a big frame, a 1024px crop would balloon into a full-body shot - so instead the crop grows from the face itself: roughly four face-widths across and five face-heights tall, with a 256px floor so a tiny face still gets a usable identity reference. The crop never exceeds crop_size and, critically, never enlarges the source image. Second, the geometry is face-aware: the vertical placement reserves extra room below the face (35/65 split) so you get shoulders and upper torso, which is the context that keeps an edited face anchored to the body.

How it works

Given the selection from RegionEditFaceSelect (which carries the face bbox), it computes a desired context envelope, aligns it to 16px (crop_size step is 64, but the final size is rounded to a 16-multiple), and clamps it into the image bounds. Where the crop would run off the image edge, it pads with replicate (edge-pixel extension) instead of black, so the VAE doesn't see a fake dark border. The result is a clean square face_context_crop plus a report_json that logs the adaptive size, the crop rect, the face's size ratio inside the crop, and the vertical position ratio - the numbers you'd want if you're debugging why a face sits oddly in frame.

The output is also 16-aligned and consistently framed, which matters for the whole pack's premise: this crop can feed RegionEditFaceSemanticCrop or go straight to the model, and its coordinates stay well-defined for the strict composite later.

Inputs and outputs

  • image - the source. The selection's recorded dimensions must match, or it throws (it won't silently crop the wrong region).
  • selection - the FACE_LOCAL_SELECTION from RegionEditFaceSelect.
  • crop_size - the hard maximum side (default 1024, range 256–4096). Set it to your model's native resolution and forget it.

One output image (face_context_crop) plus report_json. That's the whole node.

Install

ComfyUI Manager → search "Region Edit Toolkit" (package ID native-region-tile-planner-merge) → install → restart. Or git clone https://github.com/Liu-Bot24/ComfyUI-Region-Edit-Toolkit.git into ComfyUI/custom_nodes and pip install -r requirements.txt into ComfyUI's Python environment. Python 3.10+; deps numpy, Pillow, scipy, argostranslate. No models.

Gotchas

The one thing that trips people up: if you raise crop_size expecting a bigger crop, you won't get one unless the face is big enough to justify it. The node prefers face-relative sizing over hitting your target, because a distant face needs a tighter frame, not a bigger one. If your crop comes back smaller than you asked, that's the ceiling-vs-target design working as intended - check report_json's adaptive_crop_size to confirm. And don't reuse this node's output as the edit crop and expect pixel-exact replacement; it's the reference-context crop. The actual edit planning with masks and coordinates is RegionEditFaceSemanticCrop's job.

CategoryRegion Edit Toolkit/Geometry

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
selectionFACE_LOCAL_SELECTION
crop_sizeINT1024256–4096

Outputs (2)

NameTypeDescription
face_context_cropIMAGE
report_jsonSTRING