OpenCV reduceArgMax_0
Find the brightest row or column — reduceArgMax_0
- src
- dst
- nparray
reduceArgMax_0 answers a surprisingly common question: where is the maximum? Not what it's worth - where it lives. Given an image (or any matrix), it returns the index of the maximum value along one axis, as a vector of integer positions.
That's the "argmax" operation from numpy, exposed through OpenCV by opencv-comfyui (geroldmeisinger/opencv-comfyui). The real-world use in ComfyUI is peak location. Run your image through a channel-mean or threshold, then argmax a row to find which column holds the bright spot - a laser dot, a highlight, the leftmost pixel of a detected object. It's the plumbing for "find the thing without a detector."
The inputs that matter
src- anNPARRAY, straight fromImage2Nparray. Grayscale is the sane choice; a raw BGR frame will argmax across the whole thing and mostly report channel noise.axis- the direction to scan.0finds, for each column, the row index of its max - output is a row of length = image width.1finds, for each row, the column index of its max - output is a column of length = image height. (Yes, it's the same convention asreduce_0'sdim, and yes, everyone reverses it at least once.)lastIndex- a boolean.Falsereturns the first occurrence of the max;Truereturns the last. Matters when a value ties - say, an all-black row where the max is zero everywhere.dst- optional out-parameter from OpenCV's call-by-reference style; leave it unconnected.
Output is an nparray of integer indices. Like its sibling reduce_0, it is not an image - don't feed it to Nparrays2Image. Wire the index into a math or routing node instead.
Installing it
ComfyUI Manager (search "opencv-comfyui"), or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
restart, and confirm OpenCV is there:
pip install opencv-contrib-python
The gotchas
First, ties. If a row is uniformly dark, argmax returns the first pixel with that value - which is arbitrary but deterministic, and lastIndex flips it. Second, remember the axis direction: axis=0 gives you row indices, axis=1 gives column indices. Third, and this is the pack-wide rule: everything runs on NPARRAY, BGR, 0–255 numpy arrays, so the Image2Nparray in and Nparrays2Image out bridge is your friend - just don't expect the argmax output itself to be a viewable image.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| axis | INT | — | |
| lastIndex | BOOLEAN | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |