图像分区 · 遮罩区域 Lab 匹配
Fix the color mismatch without the masked-zero bias that ruins every other match
- target
- reference
- generation_mask
- harmonized_image
- report_json
The telltale sign of a badly composited local edit isn't a seam - it's a color difference. The regenerated region is the right object but the wrong temperature: too warm, too magenta, too flat. RegionEditMaskedGlobalLabMatch is the pack's answer to that specific problem: it matches the overall Lab color of the edited region to the surrounding source context, so the pasted region stops shouting "I was rendered somewhere else."
What separates it from a naive color match is how it treats the mask. Most color-match implementations treat the generation mask as a compositing mask and run their statistics on the masked-out (generated) pixels - which is exactly backwards, because those are the pixels you want to change, and they bias the transfer. This node treats generation_mask as an exclusion mask for statistics: only pixels outside it contribute to the Lab transfer. The corrected tile can then be handed to the strict composite, whose own writeback alpha remains authoritative. That's the "without masked-zero bias" in the title, and it's the whole reason the node exists rather than being a standard color-transfer utility.
How it works
You give it a target (the edited crop, out of color), a reference (the source crop it should match against), and the generation_mask (which pixels are the edit). It computes Lab statistics on the reference's non-masked context, then applies a global Lab transfer to the target at strength (default 0.85 - strong but not full, so you don't overcorrect into banding). minimum_context_pixels (default 4096) is a guard: if there aren't enough unmasked context pixels to compute a trustworthy statistic, it refuses rather than extrapolating from a handful of pixels. The docstring's phrasing - "the generation mask is an exclusion mask for statistics, not a compositing mask" - is the sentence to internalize.
Outputs: harmonized_image (the color-corrected crop, ready for the composite) and report_json. The color_harmonization_contract_version string is the usual version-locked internal agreement; leave it alone.
Inputs that matter
target/reference- the edited crop and its source counterpart, aligned.generation_mask- the edit region. Wire this correctly or the whole node is wrong: it's an exclusion mask for stats, not a paste mask.strength- 0.85 default; drop toward 0.5 if the result looks flat or the reference context is noisy.minimum_context_pixels- raise it if your edits are so large that barely any context remains; the node will error and tell you, which is the honest behavior.
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
This is a global Lab match - it fixes overall color, not spatially varying lighting. If your edit region sits under a shadow while the reference context is lit, the global correction will be wrong (that's the pack's other node, RegionEditMaskedSpatialColorFieldMatch, which does spatially-varying matching). And because it operates in Lab, it can shift hue in ways that surprise you on saturated colors - check the result, don't trust it blind. The right order in a workflow is: edit → high-frequency transfer (texture) → Lab match (color) → strict composite.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| target | IMAGE | — | |
| reference | IMAGE | — | |
| generation_mask | MASK | — | |
| strength | FLOAT | 0.850–1 | — |
| minimum_context_pixels | INT | 40961–268435456 | — |
| color_harmonization_contract_versionopt | STRING | face-local-exact-valid-context-lab-v1 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| harmonized_image | IMAGE | — |
| report_json | STRING | — |