图像分区 · 人脸阈值差异与核心
The literal, explainable difference mask — no perception, just pixels
- source_local
- generated_local
- processing_support_mask
- selection
- full_target_mask
- generated_face_mask
- automatic_union_mask
- mandatory_head_face_core
- threshold_difference_transition
- red_cyan_difference_preview
- processing_support_passthrough
- report_json
Some problems want a smart solution, and some want you to be able to explain the result to a skeptical client. RegionEditFaceThresholdDifferenceMask is the literal one. Where its sibling RegionEditFaceAdaptiveDifferenceMask builds a smoothed perceptual field with soft transitions, this node does exactly what it says on the tin: for each aligned pixel between the source crop and the generated crop, it takes the maximum absolute difference across the three 8-bit RGB channels, and any pixel at or above a threshold is kept from the AI result. That's the entire algorithm, and it's auditable.
It's the face-pipeline version of the pack's generic RegionEditAlignedDifferenceMask, specialized for the face workflow's conventions - it takes the same processing_support_mask discipline and adds a mandatory head/face core so a face edit never ends up with holes where the model made a subtle change.
How it works
Two images (source_local, generated_local), aligned, plus the processing_support_mask, the crop coordinates (x/y/width/height), and threshold_level. Notice the range: 6 to 8, default 7. That's a deliberately narrow window - the node exists for the case where you know roughly where the "changed enough to keep" line sits in 8-bit difference units, and you want to tune within a point or two. (The adaptive variant gives you the wide perceptual range; this one gives you precision in a small one.)
mask_mode is the one real decision:
difference_plus_mandatory_core(default) - the literal difference partition plus the complete semantic head/face union kept unconditionally, so the AI's whole face always makes it through.pure_difference- just the literal threshold partition, nothing added. Use this when you genuinely want the mask to be nothing but "pixels that changed," e.g. for debugging or when the core union would overreach.
Optional inputs let you feed in selection, full_target_mask, generated_face_mask, and a core_guard_face_ratio if you want the mandatory core shrunk or grown relative to the face.
Outputs: automatic_union_mask, mandatory_head_face_core, threshold_difference_transition, red_cyan_difference_preview, processing_support_passthrough, and report_json. The preview (source red, generated cyan) is the fastest way to confirm the two crops are actually aligned before you trust any mask built from them.
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 custom_nodes, pip install -r requirements.txt into ComfyUI's Python, restart. Python 3.10+, deps numpy/Pillow/scipy/argostranslate, no models.
Gotchas
The 6–8 threshold range is a feature, not a limitation: this node is for when you want the literal answer, and the adaptive node is for when you want the right-looking answer. If you find yourself fighting the threshold because subtle lighting changes grab the whole mask, you've picked the wrong tool for the job - switch to the adaptive variant. And remember both nodes are workflow-internal: they consume the same aligned crops the composite will use. Mismatched dimensions or coordinates, and the strict-composite guarantee upstream is gone before you even get there.
Inputs (13)
| Name | Type | Default | Description |
|---|---|---|---|
| source_local | IMAGE | — | |
| generated_local | IMAGE | — | |
| processing_support_mask | MASK | — | |
| x | INT | — | |
| y | INT | — | |
| width | INT | — | |
| height | INT | — | |
| threshold_level | INT | 76–8 | — |
| selectionopt | FACE_LOCAL_SELECTION | — | |
| full_target_maskopt | MASK | — | |
| generated_face_maskopt | MASK | — | |
| core_guard_face_ratioopt | FLOAT | 0.0060–0.05 | — |
| mask_modeopt | COMBO | difference_plus_mandatory_core | 2 options: difference_plus_mandatory_core, pure_difference |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| automatic_union_mask | MASK | — |
| mandatory_head_face_core | MASK | — |
| threshold_difference_transition | MASK | — |
| red_cyan_difference_preview | IMAGE | — |
| processing_support_passthrough | MASK | — |
| report_json | STRING | — |