Match Color (SBTools)
Make one image wear another's color palette — Match Color is the secret to batch consistency
- target_image
- target_alpha
- reference_image
- reference_alpha
- IMAGE
- RGB
- ALPHA
The problem: you've generated a batch of images, or you've cut subjects out of photos, and every single one has a slightly different color cast. One is warm, one is flat, one leans green. Composite them together and it's immediately obvious they don't belong in the same frame. Match Color is the node that fixes that - it transfers the color distribution of a reference image onto your target image so they finally agree.
This is the "match color distribution" half of the pack's trio of Match nodes (with Match Color Balance for temperature/tint and Match Luminance for brightness). Note that the README marks all three as "in development," and it shows in the polish - but the core functionality works and is genuinely useful.
How it works
The algorithm is MKL - Monge-Kantorovich Linearization. Without getting lost in the math, it's an optimal-transport flavor of color transfer: instead of just matching the average color (the crude "auto white balance" approach), it matches both the mean and the covariance of the color distribution, so the whole spread of colors lands where the reference expects them. It's the difference between "shift everything warmer" and "make the warm/cool relationship between shadows and highlights match too."
The color_space choice is the interesting part:
- Lab - perceptually uniform. Matching happens in a space where equal numeric changes look like equal visual changes. Good default for photographs.
- RGB - couples brightness and color together. More aggressive, sometimes useful for strong stylized looks.
- Adaptive - runs both and blends the results automatically. The "I don't want to think about it" option, and usually the best quality per the tooltip.
strength runs 0–5, where 0 is no change, 1 is a full match, and anything above 1 is deliberate overcorrection. Start at 1 and dial back.
The inputs that matter
target_image- the image being corrected (the one that needs to change).reference_image- the image whose color statistics get matched. This one is required. The node raises an error if you leave it disconnected, which is the most common "it's broken" moment - you connect only the target and wonder why nothing happens.color_spaceandstrength- covered above.target_alpha/reference_alpha- optional MASK inputs. Hand these a mask and the color statistics are computed only over the masked region. This is how you match, say, just the subject while leaving the background alone, or ignore a bright blob that would otherwise skew the whole match.
The outputs are IMAGE (the matched result), plus RGB and ALPHA - the separated channels, so you can rewire them or inspect what happened.
Installing it
Part of the ComfyUI-SBTools pack. ComfyUI Manager → search "ComfyUI-SBTools" → Install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/Amatsukast/ComfyUI-SBTools.git
cd ComfyUI-SBTools
pip install -r requirements.txt
This is the node that actually needs one of the two dependencies: kornia (the MKL math runs through it). The Manager install handles it; the manual pip install -r requirements.txt above covers it too.
Troubleshooting
- "reference_image is required" error - you found the gotcha above. Wire a reference image in.
- Result looks muddy - knock
strengthbelow 1. A full MKL match is statistically exact and can flatten the target's own character; 0.5–0.8 often looks more natural. - Colors drift toward an ugly cast - try
Adaptiveor switch to Lab. RGB-space matching tends to pull brightness and color together in ways that surprise you.
The most useful habit: keep one "hero" reference image (a frame you've graded the way you like) and feed every new render through Match Color against it. Batch consistency without hand-grading anything.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| target_image | IMAGE | Image to be color matched (RGB or RGBA). | |
| color_space | COMBO | Lab | Color space for MKL matching (Lab: perceptually uniform, RGB: brightness-color coupling, Adaptive: automatic blend of RGB+Lab for best quality). |
| strength | FLOAT | 1.000–5 | Color matching strength (0=no change, 1=full match, >1=overcorrection). |
| target_alphaopt | MASK | Optional alpha channel for target image (overrides target_image 4th channel if present). | |
| reference_imageopt | IMAGE | Reference image for color statistics (RGB only, alpha channel is ignored). | |
| reference_alphaopt | MASK | Optional alpha channel for reference image (overrides reference_image 4th channel if present). |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| RGB | IMAGE | — |
| ALPHA | MASK | — |