Nodes/tri3d-comfyui-nodes/Get mean and standard deviation of array v5.1.0
ComfyUI Node

Get mean and standard deviation of array v5.1.0

Mean and standard deviation of an array, masked to the region you care about

By TRI3D-LC·Created 3 years ago·Updated about a year ago· 27
Get mean and standard deviation of array v5.1.0
  • input_array
  • input_mask
  • Mean
  • Standard deviation

Get mean and standard deviation computes two statistics - a mean and a sigma - from one grayscale array, but only from the pixels that fall inside a second mask. That masking detail is the whole point. Computing stats over a whole image usually tells you nothing, because the background dilutes the region you actually care about. This node lets you say "average and spread of the luminosity inside the garment" and get an honest answer.

Mechanically it's textbook: flatten both tensors, sum the mask weights, compute the weighted mean, then the weighted standard deviation - the exact same math the pack's luminosity-match node uses internally, exposed here as a standalone measurement. Both outputs come back as FLOATs.

Inputs

  • input_array - the data you're measuring, as a MASK. In practice this is usually a luminosity channel, a depth map, or a normalized grayscale signal.
  • input_mask - the region to measure. Only pixels where the mask is nonzero contribute to the mean and sigma.

Outputs

  • Mean - the mask-weighted average.
  • Standard deviation - the mask-weighted spread.

Where it fits

Three recurring uses in practice. First, as a tuning instrument: if you're auto-adjusting brightness and you need to know "is this region too dark on average," the mean tells you, and the sigma tells you how trustworthy that average is (huge sigma = mixed content, be careful). Second, as the front half of a normalization loop: paired with the pack's tri3d-renormalize_array, you measure the mean/sigma of one region, then force another region to match that distribution - the classic "make this patch of lighting look like that patch" move. Third, plain debugging: attach it to a luminance mask and it's a live readout of whether your preprocessing actually produced a sensible range.

How to install

Standard pack install - ComfyUI Manager (search "tri3d") or:

cd ComfyUI/custom_nodes
git clone https://github.com/TRI3D-LC/tri3d-comfyui-nodes
# restart ComfyUI

No model, no extra deps beyond what the pack already pulls (numpy, torch). Keep the folder name as tri3d-comfyui-nodes.

Gotchas

  • Inputs are both MASKs, and the mask is used as a weight, not a binary gate - soft mask edges slightly bias the stats. For exact numbers, threshold your mask to hard 0/1 first.
  • It measures the first frame of the batch ([0]), so if you're analyzing a batch, feed single images or slice the batch beforehand.
  • An empty mask returns 0/0 - a divide-by-zero that produces NaN rather than an error. If you ever see NaN floats flowing out of this node, your mask didn't cover anything.

It's a two-number calculator wearing a MASK-shaped interface. Boring on purpose, and the foundation for the pack's more impressive luminosity tricks. Worth having in the back pocket.

CategoryTRI3D

Inputs (2)

NameTypeDefaultDescription
input_arrayMASK
input_maskMASK

Outputs (2)

NameTypeDescription
MeanFLOAT
Standard deviationFLOAT