Nodes/Region Edit Toolkit/图像分区 · 空间低频颜色匹配
ComfyUI Node

图像分区 · 空间低频颜色匹配

Fix the 'the edited region has a different exposure' problem, without re-running the model

By Liu-Bot24·Created 2 months ago·Updated about a month ago· 1
图像分区 · 空间低频颜色匹配
  • source_local
  • generated_local
  • editable_support_mask
  • context_matched_generated
  • smooth_correction_preview
  • report_json
correction_sigma48
maximum_correction0.35

The single most common tell of a regional edit - before any detail issues - is that the edited area just doesn't match the surrounding light. The model rebuilt the crop with its own exposure, its own white balance, its own gamma, and the seam reads instantly even when the content is perfect. RegionEditMaskedSpatialColorFieldMatch exists to fix exactly that, and it's one of the smartest nodes in this pack because of what it doesn't do.

Here's the mechanism. It takes your source_local crop and your generated_local crop (both cut from the same region, same size), plus an editable_support_mask marking where the edit actually happened. It then estimates a smooth, spatially-varying RGB correction field from the untouched context pixels outside the editable support, and applies that field to the generated crop. Think of it as: the source pixels around the edit tell you how light falls across the region, and the node builds a gentle gradient of color corrections that makes the generated pixels sit in that same light. It's a Reinhard-style statistics transfer done locally rather than globally - the KB's post-processing doc calls color matching the underrated fix for exactly this job, and this is that idea taken spatial.

What it deliberately won't do: it does not copy source texture, it does not hallucinate detail, and it does not touch your replacement mask. It only shifts low-frequency color. The maximum_correction dial (default 0.35) caps how far the correction field can push a pixel - raise it when the mismatch is severe, but know that going high risks pulling the generated region toward the source's palette more than you want. correction_sigma (default 48) is the spatial smoothing scale: small values let the correction follow local light variations tightly, large values flatten it into something near-global. The output smooth_correction_preview shows you the correction field as an image, which is the fastest way to learn what sigma is doing - if it looks like a splotchy mess, your sigma is too small and you're chasing per-pixel noise.

Outputs: context_matched_generated is the corrected crop, ready to feed RegionEditStrictCoordinateComposite (which is the intended next stop - the toolkit pairs them deliberately), and report_json gives the usual diagnostic dump.

Where it sits in the pipeline: this is a "continuity" node, meant to run after the generation and before compositing, and it belongs to the object-replacement workflow (SAM3 finds the object, Klein regenerates it, this matches the light, strict composite pastes it back). If you're seeing the classic "the removal is perfect but the wall color changes at the seam" - this is the node that was built for it.

Install is pack-standard: ComfyUI Manager → Region Edit Toolkit (native-region-tile-planner-merge), or git clone https://github.com/Liu-Bot24/ComfyUI-Region-Edit-Toolkit.git into custom_nodes, pip-install requirements.txt into the Python ComfyUI actually runs, restart. It's pure CPU pixel math - numpy/scipy under the hood - so no model download and no GPU pressure.

One practical note: this node expects source_local and generated_local to be aligned crops of the same region. If your generation came back resized or shifted, fix that before you reach for color matching - correcting misalignment with a color field is how you get weird gradients. The pack is new enough that there's no community lore here yet, but the correction preview makes this one self-explanatory: when it looks right, it is right.

CategoryRegion Edit Toolkit/Color & Detail

Inputs (5)

NameTypeDefaultDescription
source_localIMAGE
generated_localIMAGE
editable_support_maskMASK
correction_sigmaINT488–256
maximum_correctionFLOAT0.350–1

Outputs (3)

NameTypeDescription
context_matched_generatedIMAGE
smooth_correction_previewIMAGE
report_jsonSTRING