Nodes/opencv-comfyui/OpenCV bitwise_or_0
ComfyUI Node

OpenCV bitwise_or_0

The union node

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

If bitwise_and is "what's in both," bitwise_or_0 is "what's in either." It keeps a pixel wherever at least one of its two inputs is non-zero - the union. For masks that's the merge operation: combine a face mask and a hands mask into one "anything worth detailing" region without any blending math. For images it's the additive composite where bright wins. It's cv2.bitwise_or wrapped as a node in opencv-comfyui, and it's one of the pack's honest, useful primitives.

How it works

Pixel-by-pixel, per channel: the result is non-zero wherever either input is non-zero. On 8-bit arrays, white (255) OR anything is white, and black OR x is x. So OR-ing two masks gives you their union - every pixel that either mask covered. This is why mask pipelines use OR to accumulate regions: you can merge any number of masks by OR-ing them one pair at a time, and the result is a single clean gate.

The inputs:

  • src1 / src2 - two same-sized NPARRAYs. Size mismatch throws an assertion, so check shapes.
  • dst (optional) - out-parameter, leave unwired.
  • mask (optional) - single-channel 8-bit limiter; the OR only writes where the mask is non-zero, elsewhere the output keeps src1.
  • Output: one nparray.

The scale trap (same as every bitwise node here)

ComfyUI core masks are float 0–1; this pack's nparrays are 8-bit 0–255, and nothing auto-converts. Feed a native 0–1 mask in and the OR is no longer a clean union - values like 0.5 partially apply and you get a murky merge that's hard to debug. Convert your masks into 0–255 OpenCV arrays before OR-ing, and keep all inputs on the same scale.

Where it fits

The detailing/masking loop from the KB's masking doc is the natural home: multiple detectors give you multiple region masks, and OR is how you fold them into one region to feed a detailer or an inpainting pass. It's also the trivial way to brighten composites - OR an image with a bright highlight mask and the bright parts stay bright. Deterministic, instant, no model involved.

Install

ComfyUI Manager → search opencv-comfyui, or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-python-contrib

Restart ComfyUI, no model downloads. The pack's known install trap is a conflicting OpenCV (Cannot import name 'guidedFilter' from 'cv2.ximgproc'), fixed by a clean reinstall. And bitwise_or_1 is this node's identical twin - same union, different overload badge, use either.

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
src1NPARRAY
src2NPARRAY
dstoptNPARRAY
maskoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY