Nodes/opencv-comfyui/OpenCV meanStdDev_1
ComfyUI Node

OpenCV meanStdDev_1

The image-statistics node that returns arrays, not strings

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV meanStdDev_1
  • src
  • mean
  • stddev
  • mask
  • nparray_0
  • nparray_1

Before the details: meanStdDev_1 and meanStdDev_0 are the same node. opencv-comfyui generates one node per cv2 overload, cv2.meanStdDev is declared for both MatLike and UMat types, and the result is two identical entries. There is nothing about the _1 that makes it better or worse. Pick either and move on - the actual interesting part is what this node does, not which twin you grabbed.

What it does: computes the mean (average pixel value per channel) and the standard deviation (spread of values per channel) of an image. Mean is your brightness number; stddev is your contrast number. Together they're the raw ingredients of color matching - Reinhard-style color transfer literally aligns one image's mean and stddev to another's - and they're the two numbers you want before you decide how to fix a "washed out" or "crushed" output in the post-processing layer.

The reason to use this node over the plain mean_1: outputs. mean_1 hands you a string literal you can't do math on. meanStdDev_1 returns actual nparrays - nparray_0 is the mean, nparray_1 is the stddev - which means you can wire them into whatever arithmetic or logic chain your workflow uses to react to the measurements. That's the difference between "I can read the brightness" and "the graph can act on the brightness."

Inputs and outputs

  • src - one NPARRAY, BGR uint8 by default.
  • mean, stddev - optional, and leave them empty; they're out-parameters in the underlying OpenCV call.
  • mask - optional; restrict the stats to the nonzero mask pixels (measure just the subject, just the sky).
  • Outputs nparray_0 and nparray_1 - small (1, N) arrays, one value per channel. Not images, despite the nparray type name. Feeding them to Nparrays2Image gets you the 'NoneType' object has no attribute 'shape' error or a nonsense thumbnail.

Setup and pitfalls

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

or ComfyUI Manager → search "opencv-comfyui" → install → restart. Needs opencv-contrib-python, numpy, torch. Standard plumbing: Image2Nparray → meanStdDev_1, and remember Image2Nparray only accepts batch_size==1. If you get Cannot import name 'guidedFilter' from 'cv2.ximgproc', another custom node is fighting your OpenCV install - the README points to a known ComfyUI_LayerStyle issue for it.

Two things that actually bite: the stats come back in BGR order (you converted from RGB on the way in), so channel comparisons against RGB-space numbers look flipped; and both outputs are per-channel arrays, not scalars, so your math nodes need to handle a one-by-N array. Sort those two out and this is the measurement node you'll actually keep in a workflow.

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
srcNPARRAY
meanoptNPARRAY
stddevoptNPARRAY
maskoptNPARRAY

Outputs (2)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY