Nodes/opencv-comfyui/OpenCV max_0
ComfyUI Node

OpenCV max_0

The 'brighter pixel wins' node

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV max_0
  • src1
  • src2
  • dst
  • nparray

max_0 does exactly one thing: it takes two arrays and keeps the larger value at every pixel. That's the entire job. No neural network, no sliders, no mystery - this is the kind of $0 deterministic operation the ComfyUI ecosystem is full of, and once you see the use cases you'll stop reaching for a diffusion pass to do compositing work.

The node is part of opencv-comfyui, Gerold Meisinger's auto-generated wrapper around ~635 standalone OpenCV functions. Because the pack generates a node per cv2 overload, you get both max_0 and max_1 - they're the same function (cv2.max) with identical inputs and outputs, just different overloads from the OpenCV type stubs. Pick either; nobody can tell the difference.

Why you'd reach for it

Element-wise max is the "union" of masks. Have two segmentation masks - one from a face detector, one from a clothing segmenter - and want to inpaint both regions at once? max them together pixel-by-pixel and every pixel that's set in either input survives. It's the same trick as a logical OR, but on float or uint8 values it also merges soft (feathered) masks gracefully instead of hard-clipping them.

It's also a compositing primitive: max of two images keeps the brighter pixel, which is how you build the cheap "light bloom" passes the post-processing world loves - max a bright-pass copy back onto the original and the highlights push through without a full blend.

The inputs and outputs

  • src1, src2 - two NPARRAY inputs (the pack's type for raw numpy arrays, in BGR uint8 0–255 by default). Same size, same type; OpenCV will complain if they don't match.
  • dst - optional, and ignore it. In OpenCV this is an out-parameter, a preallocated buffer. The README's standing advice applies: leave dst disconnected.
  • Output nparray - the element-wise maximum, ready to feed to the next node or back into Nparrays2Image to return to ComfyUI's IMAGE format.

Getting it running

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

or search "opencv-comfyui" in ComfyUI Manager. Restart, then remember the plumbing: ComfyUI images are RGB torch tensors, OpenCV arrays are BGR numpy uint8. Run LoadImage → Image2Nparray → max_0 → Nparrays2Image and you're back in image space. Image2Nparray only handles batch_size==1, so if you get "Only images with batch_size==1 are supported", slice your batch down first.

One genuine gotcha: max_0 wants two arrays, so comparing against a fixed value isn't possible without a constant nparray of the same shape. If that's actually what you wanted, you're closer to a clamp/range operation - this node is for merging two real inputs. Keep that in mind and you'll be surprised how often "whichever is brighter" is the compositing trick you needed.

Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
src1NPARRAY
src2NPARRAY
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY