Nodes/opencv-comfyui/OpenCV mean_0
ComfyUI Node

OpenCV mean_0

How bright is your image, actually? OpenCV mean_0

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV mean_0
  • src
  • mask
  • literal

mean_0 answers a deceptively useful question: what's the average value of every color channel in this image? That's it. It's cv2.mean, wrapped as a node, and it's part of opencv-comfyui - Gerold Meisinger's auto-generated pack of ~635 OpenCV functions that makes the whole traditional-CV toolbox available in the node graph.

Why bother? Because "the average brightness of a channel" is the seed of a lot of real post-processing logic, and the post-processing layer of ComfyUI is full of people re-rolling generations because "the colors are off" when a two-node measurement would tell them how off. Want to know whether your output is washed out? Run mean_0. Want a rough exposure read before you decide between a gamma curve and a brightness offset? The per-channel mean is the first number you want. It's the same statistic that color-matching tools use internally - classic Reinhard-style color transfer literally moves one image's mean and std toward another's, and this node is half of that.

Inputs and outputs

  • src - a single NPARRAY (the pack's type for raw numpy arrays, BGR uint8 by default). Feed it whatever you just converted with Image2Nparray.
  • mask - optional. Pass a mask array and the mean is computed only over the pixels where the mask is nonzero. That's genuinely handy: "average brightness of just the face," or "just the sky," if you have a segmentation mask lying around.
  • Output literal - and here's the quirk. The output is a STRING, not an array: the string repr of the per-channel mean tuple, something like (124.5, 118.2, 101.3, 0.0). OpenCV returns a Scalar (mean per channel, plus a fourth value that's usually 0), and the pack can't put a tuple on a wire, so it stringifies it.

That string output is the whole reason this node feels awkward, and it's worth being explicit about: you can't wire literal into image nodes. Wire it to a node that takes a string (a text/display node, or one of this pack's own literal inputs), or just read it in the queue results. The pack's README warns that "not every return type of nparray is actually an image" - and this one isn't even an nparray.

Getting it running

Install with ComfyUI Manager (search "opencv-comfyui") or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

restart ComfyUI, and remember the plumbing: Image2Nparray converts an RGB 0..1 torch image to a BGR uint8 numpy array, and Nparrays2Image takes you back. Image2Nparray only accepts batch_size==1.

The most common failure here is OpenCV version conflicts from other custom nodes - Cannot import name 'guidedFilter' from 'cv2.ximgproc' means two nodes disagree about which OpenCV you installed. And if you were hoping mean_0's output would feed arithmetic nodes directly, the string caveat above is your heads-up. If you want the mean as an actual array you can do math on, use meanStdDev_0 instead - it returns nparrays. For a quick brightness read, this is the one.

Categoryimage/OpenCV

Inputs (2)

NameTypeDefaultDescription
srcNPARRAY
maskoptNPARRAY

Outputs (1)

NameTypeDescription
literalSTRING