Color Map Color Exchange (MD)
Color exchange with real tolerances
- image
- mask
- image
"Make the red thing blue" is the most requested color edit there is, and the naïve version - pick the red, replace it - always bleeds into the rest of the image. mdColorMapColorExchange is the version that works: a GIMP-style color exchange that replaces colors near a source color with a target color, with a separate tolerance knob per channel so you control exactly how much bleed you accept.
How it works
Every pixel's RGB is compared to a source color. A pixel counts as "matching" when all three channels fall within their per-channel tolerance windows around the source. Matching pixels are recolored to the target while preserving each channel's original offset from the source - so instead of a flat fill, you keep the shading and detail, just in the new color. A shadowed region of the red object still reads as a shadowed region of the blue object. That offset preservation is the whole trick: it's what separates this from "paint bucket over a mask."
This is deterministic and instant, which makes it the right tool for the "one color is wrong" problem our post-processing notes say you should never solve by re-rolling a generation. It also composes well with the mask: run the exchange, or gate it to a region with the optional mask input.
The inputs that matter
- from_color / to_color - RGB as hex integers. Defaults are a tan brown (8033735) → pure red (16711680). If you're not thinking in hex, grab the values from a color node or a hex converter: 16711680 =
0xFF0000. - Red_Threshold / Green_Threshold / Blue_Threshold - the tolerances, 0 to 1, per channel. This is where the actual tuning happens. The defaults (roughly 0.1, 0.1, 0.19) are sane starting points: tight enough not to grab the whole image, loose enough to catch gradients in the source color.
- image in, image out, optional mask.
Tuning without tears
If the target region has patchy coverage (parts left unchanged), raise the threshold of the channel the source color is strong in. If the background is getting recolor speckles, lower all three. There's an inherent tradeoff: a high tolerance catches more of the target but risks catching lookalike colors elsewhere - the classic reason to pair this with a mask when your source color is common (red, which half the image can share).
Installing
Same as the whole pack:
cd ComfyUI/custom_nodes
git clone https://github.com/MdONeilsl/ComfyUI-MdColorMod
or search "MdColorMod" in ComfyUI Manager, then restart. Empty requirements.txt, pure torch, no models, GPL-3.0. The pack is new and small - if Manager can't find it, the manual clone always works.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Input image tensor. | |
| from_color | INT | 80337350–16777215 | Source color (RGB hex integer). |
| to_color | INT | 167116800–16777215 | Target replacement color (RGB hex integer). |
| Red_Threshold | FLOAT | 0.1060–1 | Tolerance for the red channel (0-1). |
| Green_Threshold | FLOAT | 0.1000–1 | Tolerance for the green channel (0-1). |
| Blue_Threshold | FLOAT | 0.1900–1 | Tolerance for the blue channel (0-1). |
| maskopt | MASK | Optional mask to restrict the adjustment area. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | The color-exchanged image. |