OpenCV mean_1
The average-pixel node's other overload
- src
- mask
- literal
Let me save you a search: mean_1 and mean_0 are the same node. opencv-comfyui generates a node per cv2 overload from the OpenCV type stubs, cv2.mean is declared twice (for MatLike and UMat argument types), and you got two entries in your node list that behave identically. There is no reason to prefer one over the other. Stop reading this paragraph and just pick mean_1 because it has a cooler number.
What the node does is simple and quietly powerful: it computes the per-channel average of an image. Feed it a numpy array (via Image2Nparray), get back the mean of every channel. In the color-post-processing world that's your first tool for diagnosing "why does this output look wrong" - a washed-out image has a mean sitting way too high, a crushed one way too low, and color-cast problems show up as the three channel means disagreeing with each other. It's the raw material of color matching: classic Reinhard-style transfer moves one image's mean and standard deviation toward a reference's, and this node gives you the mean half of that equation.
Inputs and outputs
- src - one
NPARRAY. BGR uint8 by default, because that's whatImage2Nparrayproduces. - mask - optional. Restrict the average to a region: mean of just the subject, just the sky, just whatever mask you already computed for another purpose.
- literal - the output, and the catch. It's a
STRING, not an array: the repr of the per-channel mean tuple, e.g.(124.5, 118.2, 101.3, 0.0). OpenCV returns aScalar, the pack can't wire a tuple, so you get text.
That string output shapes everything about how you use this node. You can't plug literal into an arithmetic or image node - wire it into something string-eating (a display node, or one of this pack's own literal parameters), or just read it from the queue output. If you need the mean as numbers you can do math on, that's what meanStdDev_1 is for: it returns actual nparrays.
Setup
Install via ComfyUI Manager (search "opencv-comfyui") or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
restart, and remember the bridge: ComfyUI images are RGB float tensors, OpenCV arrays are BGR uint8 nparrays, so it's Image2Nparray → mean_1, and Image2Nparray only handles batch_size==1. The classic failure is an OpenCV version clash from another pack - Cannot import name 'guidedFilter' from 'cv2.ximgproc' means two custom nodes are fighting over the OpenCV install.
One honest note: a single mean value is a blunt instrument. It tells you the average, not the distribution - a half-black/half-white image and a mid-gray image can have the same mean and look totally different. For a proper brightness/contrast read, pair this with the stddev node. But for "is this image too dark, too bright, or color-shifted," mean_1 is a two-minute answer.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| maskopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| literal | STRING | — |