ComfyUI Node Runs on cloud

ConvertImg

Make a node see the channel count it expects

By bmad4ever·Created 3 years ago·Updated about a year ago· 64
ConvertImg
  • image
  • IMAGE
toRGB

Some custom nodes are picky about whether the image they receive has 1, 3, or 4 channels - and ComfyUI's implicit conversions don't always guess right. ConvertImg exists to make the conversion explicit: you tell it you want RGBA, RGB, or GRAY, and it hands back a properly-converted image. It's the "do it my way" fix for channel mismatch errors.

The author's own description says it best: "An explicit conversion, instead of using workarounds when using certain custom nodes." This is a utility that exists to unstick you, not to do something new.

How it works

The conversion is done through OpenCV (tensor2opencv with the target channel count, then back to a tensor):

  • image - any IMAGE.
  • to - the target format: RGBA (4 channels), RGB (3), or GRAY (1).

The GRAY conversion is OpenCV's standard COLOR_RGB2GRAY luminosity flattening, which is exactly what you want for mask-like processing and thresholding chains. RGBA/RGB add or drop the alpha channel as expected.

Output: the converted IMAGE, same batch.

When you'll actually reach for it

  • A downstream node demands a 1-channel gray image and you keep getting a 3-channel error. Convert to GRAY and the error vanishes.
  • A masking node feeds an alpha channel you don't want, and dropping to RGB cleans up the downstream math.
  • You want a true grayscale for a mask: many ComfyUI mask-typed ports accept images, and a GRAY output behaves more predictably than a color image when luminance is what matters.

It's also handy after pack nodes that output images: Contour To Mask can emit RGB or GRAY, and if you grabbed the wrong one, ConvertImg fixes it without rerunning the source node.

What it won't do

It converts channels; it does not resize, crop, or adjust values. GRAY is a straight luminance flattening, so if you need per-channel selection or a specific tone curve, that's a different node. And one honest note: on most modern ComfyUI versions the core ImageConvert covers similar ground, so this node matters most on older setups or when you specifically want the OpenCV-conversion behavior this pack's nodes expect.

Install

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

or install "comfyui_bmad_nodes" via ComfyUI Manager and restart. Needs OpenCV from the pack's requirements; no models. Small node, but when a channel mismatch is blocking you, it's the fastest fix in the pack.

CategoryBmad/CV

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
toCOMBORGB3 options: RGBA, RGB, GRAY

Outputs (1)

NameTypeDescription
IMAGEIMAGE