Nodes/Region Edit Toolkit/图像分区 · 人脸阈值差异与核心
ComfyUI Node

图像分区 · 人脸阈值差异与核心

The literal, explainable difference mask — no perception, just pixels

By Liu-Bot24·Created 2 months ago·Updated about a month ago· 1
图像分区 · 人脸阈值差异与核心
  • 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
x
y
width
height
threshold_level7
core_guard_face_ratio0.006
mask_modedifference_plus_mandatory_core

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.

CategoryRegion Edit Toolkit/Face

Inputs (13)

NameTypeDefaultDescription
source_localIMAGE
generated_localIMAGE
processing_support_maskMASK
xINT
yINT
widthINT
heightINT
threshold_levelINT76–8
selectionoptFACE_LOCAL_SELECTION
full_target_maskoptMASK
generated_face_maskoptMASK
core_guard_face_ratiooptFLOAT0.0060–0.05
mask_modeoptCOMBOdifference_plus_mandatory_core2 options: difference_plus_mandatory_core, pure_difference

Outputs (6)

NameTypeDescription
automatic_union_maskMASK
mandatory_head_face_coreMASK
threshold_difference_transitionMASK
red_cyan_difference_previewIMAGE
processing_support_passthroughMASK
report_jsonSTRING