Recolor mask HSV space v5.1.0
Force one garment's colors to match another, masked region only
- image_reference
- image_mask_reference
- image_recolor
- image_mask_recolor
- IMAGE
Color matching is the silent killer of good garment compositing. You've warped a shirt onto a person, but the lighting or the dye job makes it look pasted on. This node - the HSV-space member of the pack's recolor family - fixes exactly that: it reads the color statistics of a reference masked region and forces the target masked region to have the same distribution, without touching anything outside the mask.
It's the "one-click color match" of the four recolor nodes in this pack, which is why it's the one most people reach for first. No tuning knobs, no factors - four image inputs, one output, done.
How it works
The mechanism is a channel-wise mean/variance transfer, done in HSV space. Both images are converted to HSV, the reference mask picks out the region whose statistics you want, and the target mask picks out the region you want to change. For each of the H, S, and V channels it computes the mean and standard deviation inside the masks, then rescales the target channel with the classic z-score formula:
target = ((target - target_mean) / target_std) * ref_std + ref_mean
Afterward the target's hue, saturation, and brightness distributions match the reference's. It runs on HSV_FULL (the 0–255 hue range, which avoids the wraparound problems of the 0–180 variant) and, notably, wraps the hue channel modulo 255 so colors don't explode when hue values cross the red boundary. Everything outside the target mask is preserved - the original pixels are blended back in.
The inputs that matter
All four are IMAGE tensors, and they're easy to get wrong:
image_reference- the image whose colors you want. E.g., the "ideal" garment photo.image_mask_reference- a mask covering the colored region of the reference (usually the garment).image_recolor- the image you want to change.image_mask_recolor- the mask covering the region to change.
Output: the recolor'd IMAGE with everything outside image_mask_recolor left as it was.
Installing it
Part of TRI3D-LC/tri3d-comfyui-nodes - one install for the whole pack:
cd ComfyUI/custom_nodes
git clone https://github.com/TRI3D-LC/tri3d-comfyui-nodes
cd tri3d-comfyui-nodes
pip install -r requirements.txt
or ComfyUI Manager → "tri3d-comfyui-nodes", restart, find it under TRI3D. It only needs OpenCV/numpy, but the pack installs much more.
Common issues
- Masks too loose - the statistics are computed over whatever the mask covers. If your mask bleeds into background, the color match averages in the background's hue and you get a muddy shift. Tight masks matter.
- HSV doesn't preserve exact hues - hue is a circular dimension, and modulo-wrapping helps but doesn't fix every red/pink case. If a color comes back wrong, that's the tradeoff of working in HSV; the LAB-space variant in this pack behaves differently here and is worth trying.
- Batch sizes - this node processes a single image pair (it takes the first frame of each input), so feed it one image at a time, not a batch.
If you need to control how much the color shifts, the LAB_space sibling exposes per-channel factors; if you just want "make it match," this is the one.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image_reference | IMAGE | — | |
| image_mask_reference | IMAGE | — | |
| image_recolor | IMAGE | — | |
| image_mask_recolor | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |