OpenCV subtract_1
Subtract_1 — same saturating diff, second overload
- src1
- src2
- dst
- mask
- nparray
subtract_1 and subtract_0 are the same node under two suffixes - verified in the source: identical wrapper, identical cv2.subtract call. The pack generates a node per OpenCV overload and leaves the duplicates in, so don't spend a minute deciding between them. Spend it instead on understanding the function, because cv2.subtract is quietly one of the most useful primitives in the pack.
It's element-wise subtraction with saturation: every result is clamped at zero, so nothing wraps around into the 200s when it should have gone negative. That's the difference between "difference of two frames" and "subtraction garbage". Practical jobs: motion/change detection (frame minus previous frame → a mask of what moved), the subtract-half of unsharp masking (blur a copy, subtract it, you've isolated the high-frequency detail), or any "what changed between A and B" analysis you want to wire into a mask or a region selector. Once you need it, it's everywhere.
Inputs and output:
src1/src2- NPARRAY; the same shape and depth or cv2 throws an assertion.dtype- INT;-1keeps the source depth, which is right almost always.mask- optional NPARRAY; restricts the operation to nonzero-mask pixels.dst- optional out-parameter; leave it alone.
Output is a single nparray. Note it's saturating only at the bottom - there are no negative values in the output. If you need the magnitude of a difference regardless of direction, that's absdiff_0 in the same pack.
The contract to internalize. Everything here is NPARRAY, i.e. BGR uint8 0–255 numpy arrays - not ComfyUI IMAGE tensors. Image2Nparray on the way in (batch_size 1 only; ImageFromBatch(length=1) for batches), Nparrays2Image on the way out. Learn that chain once and the whole 630+ node pack stops being mysterious.
Install. ComfyUI Manager → search "opencv-comfyui", or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
restart. Requires opencv-contrib-python, numpy, torch; if startup throws Cannot import name 'guidedFilter' from 'cv2.ximgproc', fix the duplicate OpenCV installs first. It's auto-generated, bare, and the author's own tagline is "Expect dragons!" - but the bare ones are the ones that compose well.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| src1 | NPARRAY | — | |
| src2 | NPARRAY | — | |
| dtype | INT | — | |
| dstopt | NPARRAY | — | |
| maskopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |