OpenCV extractChannel_0
Pull one color channel out of an image — the split trick that matters
- src
- dst
- nparray
extractChannel takes a multi-channel image and returns a single one of its channels as a grayscale image. It's cv2.extractChannel(src, coi), wrapped from opencv-comfyui (geroldmeisinger/opencv-comfyui), and coi is the "channel of interest" - a zero-based index. Channel 0 of a BGR image is blue, channel 1 is green, channel 2 is red. That's the whole mechanism: index in, one gray plane out.
Why bother? Because channel isolation is quietly useful in ComfyUI post-processing. You can:
- Work on one channel for masking - if a subject's brightness differs sharply in the red channel, that channel alone can be thresholded into a cleaner mask than the full-color image.
- Build "channel swap" looks - extract the three channels of one image, the three of another, and recombine (this pack has no
merge, so you'd recombine elsewhere - but extraction is the half that's free). - Extract the alpha plane of an RGBA image, or pull the V channel after an HSV conversion for brightness-only work.
One crucial gotcha, and it's specific to this pack: channel order is BGR, not RGB. Image2Nparray converts ComfyUI's RGB tensor to OpenCV's BGR before anything else runs. So coi=0 is blue, not red. If you reach for channel 2 expecting the red channel by habit from other tools, you'll silently get blue - a classic source of "why does my workflow look wrong" head-scratching. Channel indices: 0 = B, 1 = G, 2 = R (for a 3-channel image; 3 = alpha if there are 4).
Inputs and outputs
- src (NPARRAY) - the multi-channel image.
- coi (INT) - zero-based channel index: 0, 1, 2 (…3 for alpha). Must be in range or OpenCV throws.
- dst (NPARRAY, optional) - out-parameter; leave unconnected (the README tells you to skip these).
- Output: nparray - the single extracted channel as a grayscale image.
Wiring it up
Standard pack flow: Image2Nparray in, then this node, then cvtColor code 8 (GRAY2BGR) and Nparrays2Image out - because a single-channel nparray needs to become a 3-channel RGB tensor before most ComfyUI nodes will accept it. (Fun fact: Nparrays2Image handles single-channel grayscale automatically by converting to RGB, so it can sometimes save you a step.)
Install
ComfyUI Manager (search "opencv-comfyui") or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes, then restart. Dependencies: opencv-contrib-python, numpy, torch; no model downloads. Pack traps: Image2Nparray is batch_size-1 only, and the author's "Expect dragons!" warning applies to the whole auto-generated set. Its twin extractChannel_1 is identical - use this one.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| coi | INT | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |