图像分区 · 人脸自适应差异与核心
The smart difference mask for face edits that don't want a hard seam
- source_local
- generated_local
- selection
- processing_support_mask
- full_target_mask
- generated_face_mask
- automatic_union_mask
- mandatory_head_face_core
- adaptive_transition_mask
- red_cyan_difference_preview
- processing_support_passthrough
- report_json
When you regenerate a face locally, the "what changed" question is nastier than it is for objects. A face edit rarely replaces a clean shape - it nudges a cheekbone, shifts a shadow, softens a jawline - and the change lives in smooth gradients, not hard edges. A literal pixel-difference threshold either grabs too little (missing the subtle stuff, so old face bleeds through) or too much (grabbing hair texture and lighting noise, so the new face leaks into the background). RegionEditFaceAdaptiveDifferenceMask is the Region Edit Toolkit's answer: a perceptual difference mask tuned to face geometry instead of raw pixel arithmetic.
It belongs to the pack's face pipeline, which is unusually disciplined about who owns what. The short version of the philosophy: the semantic head/face core is always exact AI output - no debate, no threshold. Outside that core, the node adds a smoothed, perceptual difference field that keeps only coherent, high-confidence changes and continuously fades weak differences back to the source. Result: you get a seamless writeback alpha, not a hard stencil.
How it works
Unlike the threshold node (RegionEditFaceThresholdDifferenceMask), this one doesn't work in 8-bit integer RGB. It builds a difference field with two thresholds - low_threshold (default 0.035) and high_threshold (default 0.12) - then treats the region between them as a soft transition rather than a yes/no cut. Everything is scaled in face ratios, not pixels: difference_blur_face_ratio, connectivity_close_face_ratio, and the optional knobs (compatibility_band_face_ratio, boundary_suppression_face_ratio, difference_outer_limit_face_ratio) are all fractions of the detected face size, so the same workflow scales from a 512px portrait to a 4096px one without retuning.
The output stack tells you exactly what's what:
automatic_union_mask- the mask you actually composite with.mandatory_head_face_core- the always-exact AI head region.adaptive_transition_mask- the soft band where AI and source blend.red_cyan_difference_preview- the sanity-check view (source red, generated cyan).processing_support_passthrough- your support mask, echoed back untouched.report_json- full accounting.
Inputs that matter
The first half is plumbing you already have from the face pipeline: source_local/generated_local (aligned before/after crops), selection (from RegionEditFaceSelect), processing_support_mask, full_target_mask, and the crop's x/y/width/height. The knobs you actually tune:
low_threshold/high_threshold- the perceptual band. Wider apart = fatter soft transition; this is where you fix "the AI subtly changed the lighting and the mask caught all of it."connectivity_close_face_ratio- how aggressively small diff blobs get connected into one region. Raise it if the mask comes out speckled.
Optional generated_face_mask sharpens the core when the model's own face mask is available.
Install
Pack-wide routine: 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 custom_nodes, pip install -r requirements.txt into ComfyUI's Python, restart. Python 3.10+, deps numpy/Pillow/scipy/argostranslate, no bundled models.
Gotchas
This node consumes workflow-internal images - it is not a "give me any two images" utility. Feed it the same two aligned crops you're compositing, in the same coordinate space, or the whole face pipeline's strict-composite guarantee breaks. It's also more parameters than most people need; the defaults are genuinely well-chosen for a normal head crop, so start there and only touch thresholds if the mask visibly misbehaves. And if you want literal, explainable behavior instead of perceptual smoothing, that's exactly what the threshold variant is for - this one is for when you care about the seam.
Inputs (19)
| Name | Type | Default | Description |
|---|---|---|---|
| source_local | IMAGE | — | |
| generated_local | IMAGE | — | |
| selection | FACE_LOCAL_SELECTION | — | |
| processing_support_mask | MASK | — | |
| full_target_mask | MASK | — | |
| x | INT | — | |
| y | INT | — | |
| width | INT | — | |
| height | INT | — | |
| low_threshold | FLOAT | 0.0350–1 | — |
| high_threshold | FLOAT | 0.1200–1 | — |
| difference_blur_face_ratio | FLOAT | 0.0150–0.1 | — |
| connectivity_close_face_ratio | FLOAT | 0.0400–0.2 | — |
| generated_face_maskopt | MASK | — | |
| core_guard_face_ratioopt | FLOAT | 0.0060–0.05 | — |
| compatibility_band_face_ratioopt | FLOAT | 0.0600–0.2 | — |
| difference_full_strength_face_ratioopt | FLOAT | 0.220–0.6 | — |
| difference_outer_limit_face_ratioopt | FLOAT | 0.300–0.8 | — |
| boundary_suppression_face_ratioopt | FLOAT | 0.0600–0.2 | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| automatic_union_mask | MASK | — |
| mandatory_head_face_core | MASK | — |
| adaptive_transition_mask | MASK | — |
| red_cyan_difference_preview | IMAGE | — |
| processing_support_passthrough | MASK | — |
| report_json | STRING | — |