Nodes/opencv-comfyui/OpenCV meanStdDev_0
ComfyUI Node

OpenCV meanStdDev_0

Brightness and contrast as actual numbers

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

meanStdDev_0 is the node that measures your image instead of guessing at it. It computes two statistics per color channel: the mean (your average brightness) and the standard deviation (how spread out the pixel values are - which is, honestly, your best single-number proxy for contrast). Flat and washed out? Low stddev. Crunchy and punchy? Higher. It's the same mean/std pair that classic color-transfer algorithms use to match one image's palette to another's, and opencv-comfyui gives it to you as a two-output node.

This is one of the pack's more genuinely useful entries. Want an auto-exposure rule ("if mean < 90, boost gamma")? This is the sensor. Building a color-match workflow in the deterministic post-processing layer instead of re-rolling the generation because "the colors are off"? The mean and stddev of your reference and your target are literally the inputs that a Reinhard-style transfer needs. Measure first, then decide whether you need a gamma curve or an additive brightness bump - the KB's post-processing notes hammer this: brightness is additive, gamma is a power curve, and knowing your stats tells you which way to go.

Inputs and outputs

  • src - one NPARRAY (raw numpy array, BGR uint8 by default).
  • mean, stddev - optional, and skip them. They're out-parameters in the underlying cv2.meanStdDev call, the same "avoid the optional out-parameters" rule as dst elsewhere in the pack.
  • mask - optional. Compute the statistics over only the nonzero pixels of a mask, so you can measure just a face or just a background.
  • Outputs nparray_0 (mean) and nparray_1 (stddev) - each is a small array, shape roughly (1, num_channels), one value per channel.

Here's the gotcha that trips people: neither output is an image. They're one-by-N statistical arrays. If you wire them into Nparrays2Image, you'll hit the pack's 'NoneType' object has no attribute 'shape' family of errors, or get a nonsense 1-pixel-tall "image." Treat these as numbers on a wire: feed them into math/logic nodes that can consume nparrays, or convert them if your arithmetic chain needs scalars.

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. Plumbing is the usual: Image2Nparray (RGB float 0..1 → BGR uint8) → this node, and Image2Nparray only takes batch_size==1. Watch out for OpenCV version conflicts with other custom nodes - Cannot import name 'guidedFilter' from 'cv2.ximgproc' is the standard tell.

Where people get burned: expecting the stddev array to be an image, or forgetting that OpenCV's per-channel stats come back ordered BGR (not RGB), so if you compare channels against something you computed in RGB space, the numbers will look swapped. Keep the channel order in mind and meanStdDev_0 becomes the little measurement node you reach for every time an output "looks off" and you want proof.

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
srcNPARRAY
meanoptNPARRAY
stddevoptNPARRAY
maskoptNPARRAY

Outputs (2)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY