🅱🅱色彩替换|Replace Color
The color-swap node that's honest about being a blunt instrument
- image
- IMAGE
You hand it an image, a target color, a replacement color, and a tolerance, and it recolors the pixels that match. That's the whole contract, and it's worth knowing exactly how blunt it is before you trust it with a real image - this is a "replace flat color" tool, not a magic wand.
When it's the right tool
This is deterministic post-processing in the purest sense: no model runs, nothing is generated, so the outcome is predictable and free. That's exactly the class of job the KB's post-processing doc begs you to do with a $0 pixel operation instead of re-rolling a generation. Reach for it when you have flat, clean color regions - recolor a logo or icon, swap a uniform background color, turn a colored matte into a different colored matte, prep a color-keyed asset. If your target color is sitting on anti-aliased edges, gradients, or a photo with lighting, this will leave hard, ugly edges and a halo of missed pixels. It has one tolerance knob and no feathering. It is Photoshop's "Replace Color" dialog with the fuzziness slider and nothing else.
How it works
Read the source and the mechanism is fully visible. It converts your IMAGE tensor to PIL, then walks the pixels one by one in pure Python. For each pixel it computes the Euclidean distance in RGB space between that pixel and your target color, normalized so the result lands in 0–1, and if that distance is below your threshold, it swaps in the replacement color. Everything else keeps its original RGB. It runs per-image across your whole batch, then reassembles a tensor.
Two consequences fall straight out of that. First, it's slow: a 1024×1024 image is over a million Python-loop iterations per frame. Fine for a single still; genuinely painful on a batch of video frames - budget for it. Second, the threshold default is 0, and the comparison is strict (variance < tolerance), so with the default nothing is replaced - not even an exact match, because zero is not less than zero. The node looks broken until you raise threshold to something like 0.05–0.2. That's the single most likely "why isn't it working" post this node will generate.
Inputs and outputs
- image - any IMAGE.
- target_red / target_green / target_blue - the color you're matching, 0–255.
- replace_red / replace_green / replace_blue - the color that replaces it.
- threshold - 0–1, the matching tolerance. Keep it low for clean colors; raise it slowly as your source color varies.
One output, an IMAGE. Note the swap discards alpha: the code only looks at and writes RGB, so an RGBA input comes back as RGB with transparency dropped. If your input has a useful alpha channel, this node will flatten it.
Install
Part of the same tiny pack, and there's nothing heavy about it: zero declared dependencies, no model files, no pip install. ComfyUI Manager (search ComfyUI-BBTools) or:
cd ComfyUI/custom_nodes
git clone https://github.com/bbaudio-2025/ComfyUI-BBTools
then restart. The author - bbaudio-2025, better known for the VACE long-video toolset - keeps this as a small utility in the pack, so the node is lean and the README is one line. Worth a couple of caveats repeated: raise threshold from its 0 default, and don't expect it to handle graded or textured regions. For the honest flat-color swap it does exactly what it says.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| target_red | INT | 00–255 | — |
| target_green | INT | 00–255 | — |
| target_blue | INT | 00–255 | — |
| replace_red | INT | 00–255 | — |
| replace_green | INT | 00–255 | — |
| replace_blue | INT | 00–255 | — |
| threshold | FLOAT | 0.000–1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |