Nodes/opencv-comfyui/OpenCV normalize_1
ComfyUI Node

OpenCV normalize_1

Normalize_1 — the range-stretch twin (and the required-dst gotcha)

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV normalize_1
  • src
  • dst
  • mask
  • nparray
alpha
beta
norm_type
dtype

normalize_1 is the identical twin of normalize_0: same src/dst/alpha/beta/norm_type/dtype inputs, same optional mask, same nparray output, same cv2.normalize call. The _0 article has the full recipe. Short version here, including the gotcha that trips everyone.

One paragraph version

cv2.normalize with norm_type = 32 (NORM_MINMAX) remaps an array so its min lands on alpha and its max on beta. That's the "stretch a flat map to 0–255" move that rescues depth maps, disparity maps, and gradient maps from rendering as black rectangles. Recipe: norm_type=32, alpha=0, beta=255, dtype=0 (CV_8U), then Nparrays2Image to view. Want to check the range first? minMaxLoc_0 gives you the actual min/max to plug in.

The gotcha: dst is a required input here, because OpenCV's cv2.normalize stub doesn't mark the out-parameter as optional (the README calls this exact case out). Just wire src into dst as well - in-place normalization is supported, and the output gives you the stretched array.

It's also the right tool for a specific recurring job: a soft mask (say, feather edges from SAM or an upscaler's alpha) whose values hover between 0 and 0.1 needs to be stretched before it can drive a composite correctly. Run minMaxLoc_0 first if you want to see how flat the mask is - then this node fixes it.

Why there are two

geroldmeisinger/opencv-comfyui emits one node per OpenCV overload, and the MatLike/UMat declarations collapse onto the same NPARRAY type. normalize_0 and normalize_1 are functionally identical. Pick _0.

Installing

ComfyUI Manager → "opencv-comfyui", or:

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

restart. Dependency: opencv-contrib-python, already in most installs.

Troubleshooting

  • dst unconnected - it's required; plug src into it.
  • Still flat - norm_type must be 32 and alpha/beta set; a constant array has no range to stretch.
  • Shifted colors on preview - route through Image2Nparray/Nparrays2Image to keep the BGR/RGB flip straight.
Categoryimage/OpenCV

Inputs (7)

NameTypeDefaultDescription
srcNPARRAY
dstNPARRAY
alphaFLOAT
betaFLOAT
norm_typeINT
dtypeINT
maskoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY