Nodes/ComfyUI_Swwan/Split Image Channels (Swwan)
ComfyUI Node

Split Image Channels (Swwan)

Get the alpha back out as a mask

By aining2022·Created 10 months ago·Updated about 18 hours ago· 33
Split Image Channels (Swwan)
  • image
  • red
  • green
  • blue
  • mask

The obvious use for a channel splitter is colour work: pull R, G and B apart, mess with one, put them back. The reason you'll actually install it is more mundane - it's the cleanest way to get the actual alpha out of an RGBA image as a MASK, without going anywhere near ComfyUI's inverted Load Image mask.

That distinction causes more bad cutouts than any model does. Load Image hands you MASK as 1 − alpha (a convention built for inpainting, where white means "paint here"), so the moment you want to keep the transparency the number you have is the wrong way round. This node's mask output is the alpha itself, straight off channel four.

How it works

The name of the description field gives it away: "Splits image channels into images where the selected channel is repeated for all channels, and the alpha as a mask." So for each of the three colour channels it slices a single channel and repeats it across all three - you get three greyscale-looking RGB images, one per channel. Then it takes channel four, squeezes the singleton channel dimension off, and returns it as a MASK.

That's a genuinely useful design decision: red, green and blue come out as images you can keep processing as images, while mask comes out as a mask, a different type in ComfyUI with its own consumers. The two are not interchangeable - you can't wire an IMAGE into a MASK socket - and having the alpha arrive pre-typed saves you the Image → Mask conversion dance entirely.

To put things back together, the pack ships the inverse, Merge Image Channels (Swwan), which stacks the channels back into a single IMAGE.

Inputs and outputs

Input: image (IMAGE). Outputs, in order: red, green, blue (all IMAGE, three channels each despite carrying one channel of data) and mask (MASK).

Worth stating plainly because the source is literal about it: the alpha slice reads channel index 3. Feed an RGB image with only three channels and there is no fourth channel to slice - the mask output isn't the alpha you hoped for, it's an empty slice. Wire a genuine four-channel image in (the pack's RGBA path is the intended source) if you want that output to mean anything.

Install

Comes with the pack - there's no recommended replacement for this node, so it's a current entry point, not a legacy shim:

cd /path/to/ComfyUI/custom_nodes
git clone https://github.com/aining2022/ComfyUI_Swwan.git
cd ComfyUI_Swwan
python -m pip install -r requirements.txt

Restart, hard-refresh, search Swwan. Python 3.11+, the pack's requirements (numpy, Pillow, opencv-python, scipy, scikit-image) on top of ComfyUI's torch. Nothing to download.

Where people get burned

Greyscale is not a mask. The red output looks like a black-and-white mask and behaves like an image. Feeding it into a mask input needs a conversion node, and forgetting that is a five-minute "why won't it connect" moment.

Alpha inversion, again. If you're using this to fix a cutout pipeline, be consistent about which alpha you're working with - the loaded mask (1 − alpha) or the real one (this node). The pack's README names this as a top-three support topic, and the symptom is always the same: everything except the subject saved, or the subject saved with the background still attached.

Channel order. This is R, G, B, alpha in that order for a standard image tensor. If you've been looking at OpenCV examples where the order is BGR, your maths will be right and your colours will be wrong - the pack's cv2 paths flip channels before they reach you precisely so this node doesn't have to.

Round-tripping costs precision. Split, adjust, merge is a legitimate technique, but if you're doing arithmetic on individual channels and merging blind, small clipping errors stack. For plain channel reordering, Split → Merge is exact; for contrast or threshold work, expect to eyeball the result.

CategorySwwan/Advanced/Image

Inputs (1)

NameTypeDefaultDescription
imageIMAGE—

Outputs (4)

NameTypeDescription
redIMAGE—
greenIMAGE—
blueIMAGE—
maskMASK—