OpenCV normalize_0
Stretch any flat image to full range — the fix for everything that looks black
- src
- dst
- mask
- nparray
Every pipeline that outputs a float map has the same failure: the result renders as a black rectangle. Depth maps, disparity maps, gradient maps, difference arrays - they come out of the model or the math with values squeezed into a tiny range, and 8-bit display crushes them to nothing. normalize_0 is the fix. It wraps cv2.normalize and stretches (or shrinks) an array's values to whatever range you ask for.
What it does
With norm_type = 32 (NORM_MINMAX) it remaps the array so its minimum value lands on alpha and its maximum lands on beta. That's the "stretch to full range" everyone means when they say normalize: your 0.02–0.08 depth map becomes 0–255. It can also normalize by L1/L2 norm (norm_type 2/4 - divide by the array's norm), but MINMAX is the one you'll use 99% of the time.
The canonical recipe for "I have a washed-out map, make it visible":
norm_type=32(NORM_MINMAX)alpha=0,beta=255dtype=0(CV_8U) for a uint8 result, or-1to keep the input type- output →
Nparrays2Image→ preview
If you instead want to inspect the range first, run minMaxLoc_0 and use its min/max as your alpha/beta.
The dst quirk - read this, it'll save you a headache
cv2.normalize's signature is normalize(src, dst, alpha, beta, ...) where dst is the out-parameter. In most OpenCV functions the pack made out-params optional, but here the type stub doesn't mark dst as optional - so the generated node has dst as a required input. You must plug an NPARRAY into it.
The easy answer: plug src into dst too. OpenCV supports in-place normalization (dst can be the same array as src), so wiring your source into both slots just works and gives you the normalized result on the output. This quirk is real and documented in the pack's README as a known wrinkle.
Inputs
src,dst(NPARRAY) - source, and the required out-param (wiresrcinto it).alpha,beta(FLOAT) - target min/max for NORM_MINMAX.norm_type(INT) -32for MINMAX,2/4for L1/L2 norm division.dtype(INT) --1keep input type,0= CV_8U,5= CV_32F.mask(optionalNPARRAY) - only normalize the masked region.
Output: nparray.
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.
Troubleshooting
- "
dsthas no input" - yes, it's required; plugsrcinto it. - Still black after normalize - check
alpha/betaare 0/255 andnorm_typeis 32; MINMAX with equal min=max (a constant array) has nothing to stretch. - Looks washed out on preview - remember
Image2Nparray→Nparrays2Imagehandles the BGR/RGB flip; skip the bridge and colors come out shifted.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| dst | NPARRAY | — | |
| alpha | FLOAT | — | |
| beta | FLOAT | — | |
| norm_type | INT | — | |
| dtype | INT | — | |
| maskopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |