Image Replace Color
Swap one color out of an image — and know exactly when that's a good idea
- image
- target_color
- replace_color
- IMAGE
Image Replace Color is the node in comfyui-colornodes that actually touches pixels. Feed it an image and two colors, and every pixel close to target_color gets recolored to replace_color. Want a red background turned blue, a white T-shirt turned black, a flat green button turned gray? This is the node.
The honest framing: this is a port of WAS Node Suite's Image Remove Color (by WASasquatch, MIT licensed), which is a well-trodden community tool. Its most famous trick is the coloring-book style workflow - generate black-and-white line art, then use it to flatten a colored background into pure white or black so you get clean, printable linework. If you've seen a "remove the background color from line art" tip on r/comfyui, it was almost certainly pointing at this lineage.
How it works. For every pixel, it computes the difference from the target color, converts that difference to a grayscale "distance," and applies a threshold: pixels closer than clip_threshold get replaced, everything else stays. That threshold is the whole game.
Inputs:
image(IMAGE) - what you're processing.target_color(COLOR) - the color you want to swap out.replace_color(COLOR) - what it becomes.clip_threshold(INT, default 10, range 0–255) - how close a pixel must be to the target to be replaced. This is the only knob, and it's the one you'll actually fiddle with.
Output: IMAGE - the recolored result, ready to feed on down the graph.
Install. With the pack, via ComfyUI Manager (search "comfyui-colornodes") or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/akierson/comfyui-colornodes
Restart ComfyUI. No extra pip dependencies - PIL, numpy and torch are already bundled with ComfyUI - and no models to download.
Where people get burned. This is a blunt instrument, and it's worth knowing the edges before you expect magic:
- Threshold too high eats neighbors. Replacing white at threshold 30 will also flatten light grays and soft shadows. Start low (5–10) and nudge up only if the target color isn't fully caught.
- Threshold too low leaves speckles - stray pixels of the old color clinging to edges, especially where the color meets antialiased text or curves.
- It doesn't handle anti-aliasing. Text and smooth gradients get fringed where partially-blended pixels fall either side of the threshold. This is the classic flat-color trade-off; if you're trying to swap a color in a photograph, this is the wrong tool. Photos are full of shadows, lighting shifts and gradients, and no single RGB threshold catches a red shirt under uneven light.
- The color you see isn't the color that's stored. JPEG compression and monitor calibration mean the "white" in your image is rarely
#ffffff. Sample the actual pixel value instead of guessing, or you'll be chasing a color that doesn't exist.
None of that is a flaw in the port - it's the nature of color-keying by threshold, and it's exactly why this node is perfect for flat graphics, icons, UI mockups and line art, and quietly terrible for photos. Use it for what it's good at and it's a genuinely handy single-knob tool.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| target_color | COLOR | — | |
| replace_color | COLOR | — | |
| clip_threshold | INT | 100–255 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |