cd ComfyUI/custom_nodes/
git clone <repo-url> ComfyUI-Product-Recolor
# or just copy the foldercd ComfyUI-Product-Recolor
pip install -r requirements.txtInstall ONE of these for product masking:
Option A: SAM (Recommended)
# ComfyUI-Impact-Pack (includes SAM integration)
cd ComfyUI/custom_nodes/
git clone https://github.com/ltdrdata/ComfyUI-Impact-PackOption B: GroundingDINO + SAM
cd ComfyUI/custom_nodes/
git clone https://github.com/IDEA-Research/GroundingDINOOption C: rembg (simple background removal)
pip install rembg onnxruntimeSingle-zone recoloring. Connect a mask + target RGB β recolored image.
| Input | Type | Description |
|---|---|---|
image |
IMAGE | Source product photo |
mask |
MASK | Region to recolor (from SAM) |
target_r/g/b |
INT | Target RGB values (0β255) |
luminance_blend |
FLOAT | 0.0 = keep original brightness, 1.0 = match target exactly. Recommended: 0.5β0.7 |
saturation_boost |
FLOAT | 1.0 = no change, >1 = more vivid |
edge_feather |
INT | Blur mask edges (pixels) for smooth blending |
Recolor multiple zones at once. Takes up to 8 masks + a JSON config.
K-Means clustering to auto-detect color zones within a product mask. Outputs up to 8 separate zone masks.
Process ALL colorways in a single pass. Input JSON array of colorway definitions β batch of recolored images.
Parse "R, G, B" strings into individual values.
Generate color swatch images for visual comparison.
βββββββββββββββ ββββββββββββββββ βββββββββββββββββββ ββββββββββββ
β Load Image βββββββ SAM Segment βββββββ π¨ Precise LAB βββββββ Save β
β (KT4116) β β (pants) β β Recolor β β Image β
βββββββββββββββ ββββββββββββββββ β β ββββββββββββ
β target: 66,17,34β
β lum_blend: 0.6 β
βββββββββββββββββββ
Steps:
- Load source product image
- SAM: Click on the pants β generates mask
- Precise LAB Recolor: Set target RGB from colorway spec
- Save / preview
ββββββββββββββ ββββββββββββββββ
β Load Image βββββββ SAM Segment ββββ mask_0 (main body)
β (JD1906) β β (3 clicks) ββββ mask_1 (stripes)
ββββββββββββββ βββββββββββββββββββ mask_2 (logo)
β
βΌ
ββββββββββββββββββββ ββββββββββββ
β π¨ Multi-Zone βββββββ Save β
β LAB Recolor β β Image β
β β ββββββββββββ
β zone_config JSON β
ββββββββββββββββββββ
zone_config for JX0732 (Turqoise):
[
{"mask_index": 0, "r": 88, "g": 148, "b": 134, "label": "Main"},
{"mask_index": 1, "r": 4, "g": 0, "b": 0, "label": "3 stripes"},
{"mask_index": 2, "r": 4, "g": 0, "b": 0, "label": "Logo"}
]ββββββββββββββ ββββββββββββββββ
β Load Image βββββββ SAM Segment ββββ 7 masks (one per zone)
β (TIRO25C) β β or Auto Zone β
ββββββββββββββ ββββββββββββββββ
β
βΌ
ββββββββββββββββββββ
β β‘ Batch Colorway ββββ 4 recolored images
β Processor β (JW4388, IW0454,
β β JC7027, JC7025)
β colorways JSON β
ββββββββββββββββββββ
ββββββββββββββ ββββββββββββ βββββββββββββββββββ ββββββββββββββββββββ
β Load Image βββββββ SAM/rembgβββββββ π Auto Color βββββββ π¨ Multi-Zone β
β β β (product)β β Zone Segmenter β β LAB Recolor β
ββββββββββββββ ββββββββββββ β num_zones: 3 β ββββββββββββββββββββ
βββββββββββββββββββ
Outputs: zone masks + zone RGB info
For the best segmentation:
- SAM Model:
sam_vit_h_4b8939.pth(highest quality) orsam_vit_l_0b3195.pth(faster) - Prompt Type: Point prompts (click on the garment)
- For multi-zone: Multiple SAM passes with different point prompts
- Alternative: Use GroundingDINO with text prompts like "pants", "stripes on sleeves", "logo"
| Product Zone | GroundingDINO Prompt |
|---|---|
| Pants (full) | "pants" or "trousers" |
| T-shirt body | "t-shirt body" |
| Sleeve stripes | "stripes on sleeves" |
| Adidas logo | "adidas logo" or "brand logo" |
| Jacket main body | "jacket body" |
| Side panels | "side panel" |
| Value | Effect | Use When |
|---|---|---|
| 0.0 | Keep original brightness entirely | Source and target have similar lightness |
| 0.3 | Subtle shift | Light β slightly darker target |
| 0.5β0.7 | Recommended default | Most colorway changes |
| 0.8β0.9 | Strong shift | Light β very dark (e.g., white β navy) |
| 1.0 | Match target brightness exactly | Maximum color accuracy, may lose some shadow detail |
| Value | Effect |
|---|---|
| 0 | Hard edges (visible if mask isn't perfect) |
| 2β3 | Slight softening (recommended) |
| 5β10 | Smooth blending (for imperfect masks) |
| Value | Effect |
|---|---|
| 0.5 | Muted/desaturated |
| 1.0 | Natural (default) |
| 1.2β1.5 | More vivid (useful for faded source photos) |
See examples/colorway_configs.json for complete configs matching:
- Article #1: D4T TEE (3 zones: main, 3bar, logo)
- Article #2: D4T KNIT PANT (1 zone: main)
- Article #3: M 3S SJ T (3 zones: main, stripes, logo)
- Article #4-B: W ESS 3S TS (3 zones: main, stripes, logo)
- Article #5: TIRO25C AW JKTW (7 zones: main, stripes, logo, sleeve, panels, piping)
Test the recoloring without ComfyUI:
# Single color
python test_recolor.py --image product.png --target_rgb 66,17,34
# Multi-zone
python test_recolor.py --image tshirt.png --zones 3 --target_rgbs "88,148,134;4,0,0;4,0,0"
# Batch from config
python test_recolor.py --image pant.png --config examples/colorway_configs.json \
--article article_selection_2_d4t_knit_pant
# Just analyze zones
python test_recolor.py --image jacket.png --zones 7For high-volume processing (100+ colorways), consider:
- ComfyUI API mode β Script the workflow via HTTP API
- Standalone Python β Use
test_recolor.pywith batch configs - Nano Banana Pro β Deploy as serverless endpoint
from nodes.recolor_nodes import PreciseLABRecolor, BatchColorwayProcessor
import torch
from PIL import Image
import numpy as np
# Load image as tensor
img = np.array(Image.open("product.png").convert("RGB")) / 255.0
img_tensor = torch.from_numpy(img).float().unsqueeze(0)
# Load mask (from SAM or any source)
mask = np.array(Image.open("mask.png").convert("L")) / 255.0
mask_tensor = torch.from_numpy(mask).float().unsqueeze(0)
# Recolor
node = PreciseLABRecolor()
result = node.recolor(img_tensor, mask_tensor,
target_r=66, target_g=17, target_b=34,
luminance_blend=0.6)
# Save
out = (result[0][0].numpy() * 255).astype(np.uint8)
Image.fromarray(out).save("recolored.png")ComfyUI-Product-Recolor/
βββ __init__.py # ComfyUI entry point
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ nodes/
β βββ __init__.py
β βββ recolor_nodes.py # All custom nodes
βββ examples/
β βββ colorway_configs.json # Adidas article color specs
βββ test_recolor.py # Standalone testing script
Developed for the GEN AICG PP β Colorways Pipeline
Wiethe Content GmbH β Head of AI