Nodes/tri3d-comfyui-nodes/Renormalize the layer to have the given mean and standard deviation v5.1.0
ComfyUI Node

Renormalize the layer to have the given mean and standard deviation v5.1.0

The stats-transfer workhorse

By TRI3D-LC·Created 3 years ago·Updated about a year ago· 27
Renormalize the layer to have the given mean and standard deviation v5.1.0
  • input_array
  • input_mask
  • Output array as mask
input_mean1.000
input_standard_deviation1.000

This node does one thing and does it precisely: it takes a mask/layer, z-scores it, and re-stamps it with whatever mean and standard deviation you give it. The name is the full spec - "Renormalize the layer to have the given mean and standard deviation" - which is refreshingly honest for a pack where node names are usually one-word hints.

Why would you want that? Because layers in these pipelines live on different brightness scales. A depth map from one model sits at a different range than one from another; a lighting layer you want to reuse needs its values normalized before it'll blend correctly. This is the "make this layer's statistics match a target" tool, and its companion tri3d-get_mean_and_standard_deviation measures the source stats so you can feed them in. Together they're a two-node transfer: measure the target's mean/std, plug them into this node.

How it works

The math is a masked z-score transform. It computes the mean and standard deviation of the input layer inside the masked region only, rescales:

output = ((input - in_mean) / in_std) * sigma_target + mean_target

and then blends the result back so the values outside the mask keep their original statistics - the mask defines which region gets renormalized, and the rest of the layer is preserved. The inputs are the layer (input_array) and the region-defining input_mask, both as MASK types, plus the two FLOAT targets input_mean and input_standard_deviation (both 0–2, default 1).

One nuance: because everything is clamped to the 0–2 range and masks are typically 0–1 tensors, the practical use is normalizing a region toward a reference's stats rather than to arbitrary values. Grab the reference's numbers with the companion node, wire them in, done.

The inputs that matter

  • input_array (MASK) - the layer to renormalize.
  • input_mask (MASK) - the region to apply the transform to.
  • input_mean (FLOAT, 0–2, default 1) - target mean.
  • input_standard_deviation (FLOAT, 0–2, default 1) - target standard deviation.

Output: Output array as mask (MASK), batch-preserving.

Installing it

Standard pack install:

cd ComfyUI/custom_nodes
git clone https://github.com/TRI3D-LC/tri3d-comfyui-nodes
cd tri3d-comfyui-nodes
pip install -r requirements.txt

or ComfyUI Manager → "tri3d-comfyui-nodes", restart, under TRI3D.

Common issues

  • Batch size mismatch - if input_array and input_mask have different batch sizes, the node prints batch size of different layers donot match and returns garbage (the typo is in the source). Keep them in lockstep.
  • Near-empty masks - dividing by a tiny standard deviation amplifies noise to junk. Substantial masks, please.
  • Defaults are NOT no-ops - mean 1.0 / std 1.0 on a mask that's already 0–1 will shift it. If you want "leave it alone," set the targets to the region's current measured stats instead.

It's a quiet utility node, but in the right workflow - aligning a depth layer to a reference before compositing, or normalizing masks before they hit a model that expects a specific distribution - it's exactly the missing piece.

CategoryTRI3D

Inputs (4)

NameTypeDefaultDescription
input_arrayMASK
input_maskMASK
input_meanFLOAT1.0000–2
input_standard_deviationFLOAT1.0000–2

Outputs (1)

NameTypeDescription
Output array as maskMASK