OpenCV reduce_0
Sum, average, or max a whole row or column at once — reduce_0
- src
- dst
- nparray
reduce_0 collapses a matrix along one axis into a single row or column vector. If you've used np.mean(image, axis=0) or sum over rows in numpy, you know this operation - this is OpenCV's version of it, wrapped as a node by opencv-comfyui (geroldmeisinger/opencv-comfyui).
Why would you want that in ComfyUI? Projection-style analysis. Reduce every row of a grayscale image to its average, and you get a brightness profile you can scan for a horizon line or a scanline. Reduce down a column and you can find where a bright object starts and ends. It's not a glamorous node, but it's the primitive behind a surprising amount of "where exactly is the thing in this image" logic that doesn't need a neural network.
The inputs that matter
src- anNPARRAY, fromImage2Nparray. Grayscale works best; this is a math operation, not a pretty one.dim- which way to squash.0collapses each column into a single value and returns a row vector (length = image width);1collapses each row and returns a column vector (length = image height). Same convention asreduceArgMax'saxis.rtype- the reduction itself.0= sum,1= average,2= max,3= min. Average is the one you'll reach for 90% of the time.dtype- output data type as an int.-1keeps the source type; otherwise you pick an OpenCV type constant like5(CV_32F). Leave-1unless a downstream node complains.dst- an optional out-parameter. This is OpenCV's call-by-reference style leaking through the generator; ignore it and leave it unconnected.
Output is a single nparray - a row or column vector, not an image. That's the README's "not every return type of nparray is actually an image" warning made flesh. Don't feed a 1-D vector into Nparrays2Image and expect a viewable frame; wire it into whatever math or comparison node you're using for the analysis instead.
Installing it
ComfyUI Manager (search "opencv-comfyui"), or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
restart, then make sure OpenCV is installed:
pip install opencv-contrib-python
No models, no GPU - pure CPU numpy math.
Where people get tripped up
dim is easy to reverse, and the OpenCV docs don't help - one misleading sentence says 0 gives a column. Check the source semantics instead: dim=0 collapses each column and returns a row vector (length = image width), dim=1 collapses each row and returns a column vector (length = image height). Double-check the direction before you wonder why your profile has the wrong shape. And remember the whole pack runs on NPARRAY, so the standard Image2Nparray in / Nparrays2Image out bridge applies everywhere else - it just doesn't apply here, because this node's output isn't an image. If that distinction is confusing, you're not alone; it's the pack's central design decision.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| dim | INT | — | |
| rtype | INT | — | |
| dtype | INT | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |