Nodes/opencv-comfyui/OpenCV norm_0
ComfyUI Node

OpenCV norm_0

L1, L2, and infinity norms as a single number

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV norm_0
  • src1
  • mask
  • float
normType

norm_0 wraps cv2.norm(src1, normType, mask) - it reduces an entire array to a single scalar that says how big it is. Not its width or height, but its magnitude: how much "stuff" the values contain. It's a measurement node, and it's quietly useful for validating what your pipeline just produced.

What the numbers mean

The normType input is a raw int (no dropdown - this pack's cross to bear). The ones you'll actually use:

  • 4 = L2 (Euclidean): the square root of the sum of squares. The "energy" of the array. The default in most contexts and the one to reach for first.
  • 2 = L1 (Manhattan): the sum of absolute values. More robust to outliers than L2.
  • 1 = INF: the maximum absolute value - "how big is the single biggest element".
  • 5 = L2SQR: sum of squares without the square root, if you want to avoid the sqrt for comparisons.

The optional mask input restricts the calculation to a region - handy if you want the energy of just a crop or a foreground.

Why you'd reach for it

Concrete ComfyUI uses:

  • Sanity-check a gradient or edge map. A high L2 norm means the array is "lively"; a near-zero norm means your image flattened to a constant (a failed blur, an all-black mask).
  • Measure the amount of change. Pair with norm_2 (the difference version) if you want between arrays; this one measures a single array.
  • Energy of a feature map before you decide how aggressively to process it.

It's a scalar, so it wires straight into routing logic - compare the value to a threshold and you've got a simple "is this mask empty/dense?" gate.

Inputs and outputs

  • src1 (NPARRAY) - the array to measure.
  • normType (INT) - one of the codes above.
  • mask (optional NPARRAY) - restrict to a region.
  • Output: float - the norm.

Nothing here is an image, so the output ends the chain - don't feed it into Nparrays2Image.

Installing

Part of geroldmeisinger/opencv-comfyui. ComfyUI Manager → "opencv-comfyui", or:

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

restart. Dependency: opencv-contrib-python, almost always already installed.

Troubleshooting

  • Values all zero when you expected big numbers - check normType; INF only reflects the single largest element, so a mostly-zeros array scores low on L1 but can be high on INF.
  • Wrong dtype errors - norm works on numeric arrays; make sure src1 came from Image2Nparray or another OpenCV node, not a raw Comfy IMAGE.
  • Which variant - norm_0 and norm_1 are identical duplicates (overload residue). Use _0.
Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
src1NPARRAY
normTypeINT
maskoptNPARRAY

Outputs (1)

NameTypeDescription
floatFLOAT