ComfyUI Node Runs on cloud

AddAlpha

Give a flat RGB image a real alpha channel

By bmad4ever·Created 3 years ago·Updated 9 months ago· 70
AddAlpha
  • rgb_image
  • alpha
  • IMAGE
methoddefault

ComfyUI is mostly RGB. Images come out of loaders and samplers as three-channel tensors, and if you want transparency you have to add it yourself. AddAlpha is the tiny utility that does exactly that: it takes an RGB image, optionally an alpha (a mask), and returns a four-channel RGBA image where the alpha plane says which pixels are opaque and which are see-through.

The most common setup is compositing. You've cut an object out of one image with a segmentation or masking pass, and you want to layer it over a new background. ComfyUI's built-in "composite" nodes are happier when the foreground already carries its alpha in the image itself - that's what AddAlpha produces. Wire rgb_image in, wire your mask into alpha, and out comes a transparent-capable image you can drop onto a background.

Inputs and how it behaves

  • rgb_image (required) - the image that becomes the RGB part.
  • alpha (optional) - the transparency map. If you leave it disconnected, the output is just the RGB image with a fully opaque alpha channel - not useless, but not the interesting case.
  • method - default or invert. Invert flips the alpha (255 − alpha), which is the exact tool for when your mask is inverted relative to what you want. Say your segmentation node hands you a mask where background is white; one click of invert and it's correct.

Under the hood it's cvtColor RGB→RGBA, then it overwrites the alpha plane from your mask (or its inverse). If the mask you feed in is a color image, it gets converted to grayscale first - only the brightness matters.

Install

Part of bmad4ever/comfyui_bmad_nodes:

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

Restart, or use ComfyUI Manager → search comfyui_bmad_nodes. The pack's dependencies (opencv-python~=4.8.1.78, scikit-image, gray2color, simpleeval) install via Manager; no model files anywhere in this pack.

Gotchas

Two things are worth knowing. First, the output is still typed IMAGE in ComfyUI's terms - the extra channel rides along inside the tensor, so any node downstream that assumes three channels (a lot of them do) may ignore or drop the alpha. Route it into nodes that actually read RGBA, like a proper composite or a save-with-alpha. Second, remember method: invert exists - it's the one setting on this node people forget about, and it saves you an entire invert-mask node when your mask comes out backwards.

CategoryBmad/image

Inputs (3)

NameTypeDefaultDescription
rgb_imageIMAGE
alphaoptIMAGE
methodoptCOMBOdefault2 options: default, invert

Outputs (1)

NameTypeDescription
IMAGEIMAGE