Nodes/ComfyUI_Fill-Nodes/FL Replace Color
ComfyUI Node

FL Replace Color

Swap one color for another, with tolerance and edge control

By filliptm·Created 3 years ago·Updated about 12 hours ago· 628
FL Replace Color
  • image
  • IMAGE
source_color#FF0000
target_color#00FF00
tolerance0.10
expand_pixels0
contract_pixels0

FL_ReplaceColor does exactly what the name says: pick a source color, pick a target color, and every pixel close enough to the source gets recolored to the target. It's the pack's own description, and it's accurate - this is a genuinely simple, genuinely useful node for flat-color swaps: fixing a logo's background color, doing a rough green-screen-style key without an actual chroma-key algorithm, or cleaning up a flat-shaded illustration where one color needs to change everywhere it appears.

How the matching works. source_color and target_color are hex strings (default #FF0000 red → #00FF00 green), and both have interactive color pickers on the node itself, so you don't have to type hex codes by hand if you'd rather click a swatch. The matching isn't exact-pixel-only - it measures Euclidean distance in RGB space between each pixel and your source color, and tolerance (0–1, default 0.1) sets how close a pixel needs to be to count as a match. Low tolerance only swaps near-identical pixels; higher tolerance sweeps in a wider range of similar shades.

Two more knobs handle cleanup after the swap: expand_pixels and contract_pixels (0–100 each, default 0) run morphological operations - dilating or eroding the replaced region using a circular kernel - to grow or shrink the swapped area. That matters because color replacement based on distance thresholds tends to leave a ragged edge where anti-aliasing blends the source color into whatever's next to it; expanding the replaced region by a few pixels is often the fix for that halo rather than cranking tolerance up further and risking eating into colors you meant to keep.

One IMAGE output - the recolored result.

Installing it follows the pack's usual pattern: search "Fill-Nodes" in ComfyUI Manager, or clone it by hand -

cd ComfyUI/custom_nodes
git clone https://github.com/filliptm/ComfyUI_Fill-Nodes
  • then restart ComfyUI. No extra dependencies beyond OpenCV, already a core requirement across this pack.

Where people get burned. The tension is always between tolerance and edge quality. Set it too low and you'll get a clean interior swap but a visible ring of untouched anti-aliased pixels right at the boundary - the classic "halo" look. Push tolerance up to catch those edge pixels and you risk bleeding into adjacent colors that happen to sit close in RGB space, especially on photographic or gradient-heavy source images where "the color" isn't actually one flat value. The better fix for the halo case specifically is usually a small expand_pixels value rather than more tolerance - it closes the gap without widening what counts as a match in the first place. And remember this is working in plain RGB distance, not perceptual color space, so two colors that look similar to your eye under different lighting or saturation can be numerically far apart and won't match at a low tolerance even though you'd expect them to.

Category🏵️Fill Nodes/Image

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
source_colorSTRING#FF0000
target_colorSTRING#00FF00
toleranceFLOAT0.100–1
expand_pixelsINT00–100
contract_pixelsINT00–100

Outputs (1)

NameTypeDescription
IMAGEIMAGE