Nodes/ComfyUI_ColorMod/Convert color space
ComfyUI Node

Convert color space

The masking trick you didn't know you needed

By city96·Created 3 years ago·Updated 2 years ago· 111
Convert color space
  • image
  • IMAGE
srcRGB
dstRGB

Here's the classic problem: you want to select or adjust "the red stuff" in an image, but in RGB there's no clean "amount of red" value - every pixel is three channels that all move together. Convert to HSV or HLS and suddenly hue, saturation, and lightness are separate channels you can threshold, mask, and edit independently. That's what this node is for: it converts an image between color spaces using OpenCV, and it's the quiet workhorse behind a lot of color-masking workflows.

It's the least flashy node in the ColorMod pack and honestly one of the most generally useful.

The inputs

  • image - the IMAGE to convert.
  • src - the color space your image is currently in (default RGB).
  • dst - the one you want (default RGB). The dropdown offers RGB, BGR, HLS, HSV, YCrCb, YUV.

Output is one IMAGE in the destination space. If src and dst match, it passes the image straight through.

The workflow that makes it click

  1. Convert RGB → HSV (or HLS).
  2. Extract the channel you care about (hue for "all the red things," value/lightness for exposure), threshold it into a mask.
  3. Do whatever masked edit you're doing.
  4. Convert back to RGB before the image touches a VAE or sampler.

That last step is the one people forget. ComfyUI and diffusion models expect RGB; a stray HSV image fed to the VAE is a bug you'll chase for an hour.

Installing

From the ColorMod pack, needs OpenCV:

cd ComfyUI/custom_nodes
git clone https://github.com/city96/ComfyUI_ColorMod
cd ComfyUI_ColorMod
pip install -r requirements.txt

Restart, or install via ComfyUI Manager ("ComfyUI_ColorMod"). Node missing → opencv not installed; the console prints "Can't find opencv!" at startup.

Gotchas

  • It's 8-bit under the hood. The node converts through uint8 (multiplies by 255 and back), so it's lossy - fine for RGB work, but don't run it in the middle of a 16-bit precision pipeline. It'll silently drop the extra depth.
  • The math is BGR behind the scenes. OpenCV's default channel order sneaks in here, which is why "RGB to HSV" can occasionally surprise you on the edges. The node handles the flip for you; just don't feed the raw output to something that assumes a specific order without checking.
  • It prints min/mean/max to your console. That's the author's debugging leftover, not a bug. Ignore it.

A note on the naming: despite the intimidating "color space" wording, you don't need color-science knowledge to use this. It's just "which arrangement of the same colors do I want to work in?" and for 90% of ComfyUI users the answer is HSV for masking and RGB for everything else.

CategoryColorMod

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
srcCOMBORGB6 options: RGB, BGR, HLS, HSV, YCrCb, YUV
dstCOMBORGB6 options: RGB, BGR, HLS, HSV, YCrCb, YUV

Outputs (1)

NameTypeDescription
IMAGEIMAGE