Nodes/opencv-comfyui/OpenCV min_0
ComfyUI Node

OpenCV min_0

The 'darker pixel wins' compositing trick

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

min_0 is the mirror image of the max node, and together they're the cheapest compositing primitives in the pack. It takes two arrays and keeps the smaller value at every pixel. That's the whole operation - and "darker pixel wins" turns out to be exactly the move you want in a few surprising places.

Think of it as the intersection of masks. max gives you the union (anywhere either mask is set), min gives you the overlap (pixels that are set in both). Two overlapping segmentation masks, and you only want the region they agree on? min them. It's also a shadow/compositing tool: min two images and the dark pixels of each punch through - a way to composite a dark foreground or let shadows win. And it's the classic way to clamp from above: if one input is a constant dark value at every pixel, min becomes a "never brighter than this" ceiling.

The node is part of opencv-comfyui, Gerold Meisinger's auto-generated wrapper around ~635 OpenCV functions. And as with every function in the pack that appears twice, min_0 and min_1 are identical - one per cv2 overload (MatLike vs UMat), same behavior, pick either.

Inputs and outputs

  • src1, src2 - two NPARRAYs (the pack's raw numpy array type, BGR uint8 by default). Same size and type, or OpenCV throws.
  • dst - optional, and skip it. Out-parameter; the README's standing advice.
  • Output nparray - the element-wise minimum.

One honest limit: both inputs have to be arrays. There's no scalar overload here - you can't min against a fixed number 5 without building a constant nparray of the same shape. If that's what you were after, this node is the wrong tool; you want a clamp. If you want to intersect two real masks, it's exactly right.

Getting it running

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

or ComfyUI Manager → search "opencv-comfyui" → install → restart. Dependencies: opencv-contrib-python, numpy, torch. The bridge is the usual one: Image2Nparray (RGB float 0..1 → BGR uint8 nparray) → min_0Nparrays2Image, and Image2Nparray only accepts batch_size==1.

Failure modes are the pack's standard ones - OpenCV version clashes between custom nodes (Cannot import name 'guidedFilter' from 'cv2.ximgproc' is the tell), and treating a non-image nparray output as an image. Neither applies here since min_0 returns a real image array, but they're the first things to check if the pack misbehaves at all. Honestly, min is one of those nodes you won't use every week - but the week you need to intersect two masks, it's a two-node answer instead of a workaround.

Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
src1NPARRAY
src2NPARRAY
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY