Nodes/opencv-comfyui/OpenCV bitwise_xor_0
ComfyUI Node

OpenCV bitwise_xor_0

XOR — the mask node for 'where do these differ'

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

AND keeps what's in both, OR keeps what's in either, and XOR keeps what's in only one. bitwise_xor_0 is the exclusive-OR node: a pixel survives only when exactly one of its two inputs is non-zero. If you've ever wanted to find "where these two masks disagree," or diff two versions of an image to see what changed, this is the primitive. It's cv2.bitwise_xor wrapped as a node in opencv-comfyui, and it's the least-used but arguably most interesting member of the bitwise family.

How it works

Per-pixel, per channel: the result is non-zero when the two inputs differ, and zero when they agree. On 8-bit masks that means - white XOR black = white (they differ), white XOR white = black (same), black XOR black = black (same). XOR two overlapping masks and you get the symmetric difference: the areas covered by one but not both. XOR an image with a modified version of itself and the output lights up exactly where the pixels changed.

The inputs:

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

What it's actually for

The real use cases are the "diff" ones. In a video or animation workflow, XOR-ing frame N against frame N-1 highlights exactly what moved between them - a crude but instant motion-detection pass. In mask work, XOR is how you find disagreement: two detectors gave you different regions for the same subject, and you want to see (or fix) where they conflict. It's also a fun way to check whether a "copy" of an image is really identical - XOR should come out all black.

Same caveats as its siblings: ComfyUI masks are float 0–1 while this pack's nparrays are 8-bit 0–255 (convert, don't mix), and everything runs on NPARRAY via Image2Nparray / Nparrays2Image. The _0 version is the MatLike overload wrapper; a bitwise_xor_1 exists as the identical UMat twin, and they behave exactly the same.

Install

opencv-comfyui via ComfyUI Manager (search "opencv-comfyui"), or:

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

Restart, no model downloads. The pack's one known install trap is a conflicting OpenCV (Cannot import name 'guidedFilter' from 'cv2.ximgproc') - a clean reinstall in the right environment sorts it out.

The one-sentence takeaway

You'll reach for AND and OR constantly; XOR you'll reach for once, and it'll be the exact moment you need to know where two things differ. When that moment comes, this node is exactly what it says on the tin.

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
src1NPARRAY
src2NPARRAY
dstoptNPARRAY
maskoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY