Nodes/opencv-comfyui/OpenCV bitwise_not_0
ComfyUI Node

OpenCV bitwise_not_0

The one-input node that flips pixels

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV bitwise_not_0
  • src
  • dst
  • mask
  • nparray

The most useful "do almost nothing" node in the pack. bitwise_not_0 inverts an image: every pixel value becomes 255 minus itself. Black becomes white, white becomes black, midtones flip to their complement. In photography terms it's a perfect negative; in mask terms it's the node that turns "keep this region" into "keep everything except this region," which is a move you'll need constantly.

It wraps cv2.bitwise_not from opencv-comfyui, the auto-generated pack of OpenCV wrappers. One input, one output, nothing to misconfigure - the closest thing this pack has to a beginner-friendly freebie.

What you're setting

  • src - the NPARRAY to invert. Grayscale or color, both work.
  • dst (optional) - the out-parameter. Leave it unwired.
  • mask (optional) - a single-channel 8-bit limiter: only pixels where the mask is non-zero get inverted; everywhere else the output keeps the original value. This is how you invert part of an image instead of all of it.
  • Output: one nparray, the inverted result.

That's the whole schema. No string literals, no BGR surprises that matter here (inversion is channel-wise, so channel order is irrelevant - a nice change from the rest of the pack).

When you'll actually use it

The big one is mask logic. A mask in OpenCV-land is black-where-inactive, white-where-active; flip it and you've selected the complement. In a detailing or inpainting graph, inverting the region mask is how you say "everywhere but the face," and this is the deterministic one-node way to do it. Outside masks, it's the classic negative look for stylized output, and it's a quick sanity tool - invert, compare, learn what the pixel values actually were.

Two pack-wide things to keep in mind. First, this pack runs on NPARRAY, so images come in through Image2Nparray and go back out through Nparrays2Image. Second, keep your scale consistent: ComfyUI masks are float 0–1, OpenCV arrays are 8-bit 0–255, and this node does not convert for you. A native Comfy mask fed straight in will invert to a "complement that isn't quite a complement" because the scale is wrong.

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 one known install trap is a conflicting OpenCV (Cannot import name 'guidedFilter' from 'cv2.ximgproc'), solved by a clean reinstall. bitwise_not_1 is this node's identical twin (same function, different overload badge) - use either.

Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
srcNPARRAY
dstoptNPARRAY
maskoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY