图像分区 · 宽支持区域严格合成
Paste a local edit back without seams — or not at all
- original
- source_local
- generated_local
- selected_local_mask
- target_core_mask
- generation_support_mask
- writeback_support_mask
- protection_mask
- manual_erase_mask
- final_image
- strict_full_resolution_mask
- full_resolution_alpha
- clean_local_crop
- wide_support_alpha
- outer_crop_ramp
- difference_preview
- report_json
The hard part of local editing was never the editing - it's putting the result back. Crop a region, regenerate it in isolation, and a naive paste gives you a visible seam where the model's context ran out, or worse, silently overwrites pixels outside the region you meant to change. This node is the "put it back" step from the Region Edit Toolkit's flow, and the word in its name is doing real work: strict. It only writes pixels inside its own alpha mask, and if it catches itself about to touch anything else, it throws an error and refuses to run instead of quietly corrupting your image.
It's the wide-support variant of RegionEditStrictCoordinateComposite. Same family, same philosophy, one important difference: the model gets to generate a broad area around your edit, but only the exact crop gets written back. That matters more than it sounds. When you regenerate a crop, the sampler needs context outside the region you're replacing, or you get a hard edge right at the boundary. This node lets the generation roam over a wide "support" while you only commit the exact rectangle you actually wanted changed.
How it works
Read the source and the algorithm is honestly elegant. It builds a two-stage alpha in crop space. First a wide support alpha: the writeback region is fully opaque, the ring between generation and writeback fades by a smoothstep of the relative distance to each, and everything outside the generation support is zero. Notably, the semantic selection mask is never used as the paste boundary - that's the trick that avoids outline-shaped seams.
Then a four-side crop-perimeter ramp (outer_crop_ramp) multiplies over that, and protection and manual-erase masks zero out whatever survives. Sides of the crop that touch the original image boundary automatically get zero feather - a nice touch for full-bleed edits. The result composites into the full image, and then the node runs a ~16-point invariant gate: dimensions equal, source matches original, nothing leaked outside the mask, no overlap with protection, protection pixels are byte-identical to source. Any check fails, you get a ValueError with a message telling you exactly which invariant broke. This is a node that assumes you'll mess up, and that's a feature.
The inputs that matter
There are ten image/mask inputs and that looks terrifying. Most come from upstream Region Edit nodes, so you rarely hand-fill them:
original,source_local,generated_local- the full image, the unedited crop, and your edited crop.source_localmust be byte-identical to the original at the declaredx/y/width/height. Don't resize or upscale it in between - the node checks withtorch.equaland will refuse.generation_support_maskandwriteback_support_mask- the wide area the model edited, and the narrower area you commit. The code enforceswriteback ⊆ generation.protection_maskandmanual_erase_mask- areas that must come back untouched. Overlap the final support with these and it errors.top/bottom/left/right_feather_percent- the four-side seam softness (0–30%, defaults 10/10/5/5). These are the only knobs you'll actually tweak while iterating.
Outputs: final_image is the one you wire to a preview or save node. difference_preview is worth a look - it's |result − original|, so you can eyeball exactly what changed. strict_full_resolution_mask, full_resolution_alpha, wide_support_alpha, outer_crop_ramp, clean_local_crop are debugging/inspection outputs, and report_json dumps the whole gate report.
Installing it
Part of the Region Edit Toolkit (search Region Edit Toolkit or package id native-region-tile-planner-merge in ComfyUI Manager, or comfy node install native-region-tile-planner-merge). Via git:
cd ComfyUI\custom_nodes
git clone https://github.com/Liu-Bot24/ComfyUI-Region-Edit-Toolkit.git
cd ComfyUI-Region-Edit-Toolkit
& "<your ComfyUI python>" -m pip install -r requirements.txt
Needs Python 3.10+; deps are numpy, Pillow, scipy, and argostranslate (the argos model is only for the optional Chinese→English translate nodes - skip it unless you need those). No model files required by this node itself; the pack's example workflows separately expect SAM3 and a local Klein editor.
When it bites you
Everything this node refuses to do is documented in its own error messages. The common ones: your source_local isn't the pristine original crop (usually an upscaler or a resized crop in between - restore the exact crop size first, the README says the same), a mask that's empty, or protection overlapping the final support. The fix is almost always "wire the crop coordinates straight through instead of recomputing them." In a pack this young (and this is a niche, mostly-Chinese-documented toolkit with almost no Reddit chatter yet), the strictness is what saves you - let it fail loudly rather than fight it.
Inputs (17)
| Name | Type | Default | Description |
|---|---|---|---|
| original | IMAGE | — | |
| source_local | IMAGE | — | |
| generated_local | IMAGE | — | |
| selected_local_mask | MASK | — | |
| target_core_mask | MASK | — | |
| generation_support_mask | MASK | — | |
| writeback_support_mask | MASK | — | |
| protection_mask | MASK | — | |
| manual_erase_mask | MASK | — | |
| x | INT | — | |
| y | INT | — | |
| width | INT | — | |
| height | INT | — | |
| top_feather_percent | FLOAT | 10.00–30 | — |
| bottom_feather_percent | FLOAT | 10.00–30 | — |
| left_feather_percent | FLOAT | 5.00–30 | — |
| right_feather_percent | FLOAT | 5.00–30 | — |
Outputs (8)
| Name | Type | Description |
|---|---|---|
| final_image | IMAGE | — |
| strict_full_resolution_mask | MASK | — |
| full_resolution_alpha | MASK | — |
| clean_local_crop | IMAGE | — |
| wide_support_alpha | MASK | — |
| outer_crop_ramp | MASK | — |
| difference_preview | IMAGE | — |
| report_json | STRING | — |