Nodes/ComfyUI-Recolor/🎨 Direct Replace Recolor
ComfyUI Node

🎨 Direct Replace Recolor

Repaint a product in the exact RGB you were handed

By benjamin-bertramΒ·Created 6 months agoΒ·Updated 6 months agoΒ· 1
🎨 Direct Replace Recolor
  • image
  • mask
  • recolored
β—„target_r128β–Ί
β—„target_g128β–Ί
β—„target_b128β–Ί
β—„luminance_modeβ–Ύβ–Ί
β—„luminance_strength0.70β–Ί
β—„texture_preserve0.15β–Ί
β—„edge_feather2β–Ί

The node that does the actual repainting

Every recolor pack has a workhorse, and this is it. Feed it a product photo, a mask of the region you want changed, and a target RGB, and you get back the same image with that region recolored to exactly the color you specified - fabric folds, shading and texture intact. It's the node behind the README's "Precise LAB Recolor" workflow, and it's the first one you should learn because the whole pack is built around it.

The pack comes from an apparel company's colorway pipeline (Wiethe Content GmbH, built for generating product colorways from article specs), so "recolor this tee to RGB 66,17,34 and make it look real" is precisely the job this was written for. If you've ever tried to swap a garment's color with a hue/saturation node and watched the shading die, this is the fix.

Why LAB makes it work

The trick is in the color space. Instead of shifting RGB channels directly, the node converts the image to CIELAB (via scikit-image), where L* is lightness and a* / b* carry the actual color. The color and the lighting are no longer tangled together. So it can set the masked pixels' a*/b* to the exact target color while leaving L* alone - all the brightness variation from the source photo survives, which is what sells the result as a real photograph rather than a bucket fill.

That's also why texture_preserve exists. At 0 the color goes perfectly flat (which looks plastic on fabric). At 0.15 it re-injects a bit of the source's chroma variation so the knit or weave reads; at 0.4 you get heavy texture retention. Default 0.15 is a fine starting point.

The inputs that matter

  • image + mask - the photo and the region. Mask comes from a segmentation step (see install below); it's not generated here.
  • target_r / target_g / target_b - 0–255. This is your colorway spec.
  • luminance_mode - scale, blend, or keep. scale multiplies the source brightness toward the target's lightness (best for big lightβ†’dark jumps like whiteβ†’navy), blend adds a fixed offset, keep leaves brightness untouched. Default scale is right most of the time.
  • luminance_strength - 0–1, default 0.7. How far toward the target's brightness you go. The README's 0.5–0.7 recommendation is worth respecting.
  • edge_feather - Gaussian blur on the mask edge, default 2px. Bump to 5–10 if your SAM mask has ragged edges.

Output is a single recolored IMAGE - wire it straight into a preview or Save Image.

Install and the segmentation step

cd ComfyUI/custom_nodes
git clone https://github.com/benjamin-bertram/ComfyUI-Recolor
cd ComfyUI-Recolor
pip install -r requirements.txt

Restart ComfyUI. ComfyUI Manager also finds it by searching "ComfyUI-Recolor". The pack itself downloads no models - it's all pixel math on torch + opencv-python + scikit-image, so nothing heavy to fetch.

The mask, though, has to come from somewhere else. The README recommends installing ComfyUI-Impact-Pack for SAM (click on the garment, get a mask), or GroundingDINO + SAM for text-prompted regions, or rembg for simple background removal. For a single garment that's the core ComfyUI habit anyway: detect/mask first, edit second.

Gotchas

The node only processes image[0] - the first frame of the batch. Feed it a batch and the extras are ignored, so run single images or handle batching yourself.

And if the output looks identical to the input, your mask doesn't overlap the image content - the code returns the original image unchanged when the masked region is empty. Check that the mask came from the right frame and that it isn't all zeros.

One more, from reading the source: luminance_mode: scale only engages when the source region's mean lightness is above a threshold, so very dark garments won't get brightness-scaled. If you're going black→red and the result looks off, switch to blend.

CategoryAICG/Recolor

Inputs (9)

NameTypeDefaultDescription
imageIMAGEβ€”
maskMASKβ€”
target_rINT1280–255β€”
target_gINT1280–255β€”
target_bINT1280–255β€”
luminance_modeCOMBO3 options: scale, blend, keep
luminance_strengthFLOAT0.700–1β€”
texture_preserveFLOAT0.150–1β€”
edge_featherINT20–50β€”

Outputs (1)

NameTypeDescription
recoloredIMAGEβ€”