Nodes/opencv-comfyui/OpenCV bitwise_and_1
ComfyUI Node

OpenCV bitwise_and_1

The twin AND node — same intersection, second badge

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

bitwise_and_1 is bitwise_and_0 with a different suffix. This pack generates a wrapper per OpenCV overload, cv2.bitwise_and is stubbed twice (MatLike and UMat), and the generator doesn't dedupe - so there are two identical nodes. If you've read the _0 page, you're done. If you landed here first, the short version: this node keeps only the pixels that are non-zero in both of its inputs - the intersection of two images or two masks.

What you're setting

  • src1 / src2 - two same-sized NPARRAYs. Same size or OpenCV asserts.
  • dst (optional) - out-parameter; leave unwired.
  • mask (optional) - a single-channel 8-bit limiter: the AND only gets written where the mask is non-zero; elsewhere the output keeps src1.
  • Output: one nparray.

The everyday use is mask-and-image: AND an image with a black-and-white mask and you keep the image exactly where the mask is white - a clean, deterministic way to cut a region out without any compositing fanciness. AND two masks and you get their overlap, which is the standard way to build a refined region from coarse masks.

The scale trap

ComfyUI core masks are float 0–1; OpenCV nparrays are 8-bit 0–255. If you mix the two scales without converting, your "white" values stop being 255 and the AND gets fuzzy - not broken, just wrong in a hard-to-see way. Keep everything in one scale, and remember this pack never auto-converts for you.

Plumbing and install

Everything here runs on NPARRAY: in via Image2Nparray, out via Nparrays2Image. Install opencv-comfyui through ComfyUI Manager (search "opencv-comfyui") or:

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

Restart and you're done - no models, no downloads. The pack's only setup gotcha is a conflicting OpenCV install (Cannot import name 'guidedFilter' from 'cv2.ximgproc'), fixed with a clean reinstall.

Bottom line: _0 and _1 are interchangeable, and the whole pack is rough-hewn by design. If you need the full explanation of AND semantics and the mask gotcha, read bitwise_and_0 - this page is just the duplicate the generator left behind.

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
src1NPARRAY
src2NPARRAY
dstoptNPARRAY
maskoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY