Nodes/opencv-comfyui/OpenCV reduceArgMin_0
ComfyUI Node

OpenCV reduceArgMin_0

Locate the darkest scanline with reduceArgMin_0

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV reduceArgMin_0
  • src
  • dst
  • nparray
axis
lastIndex

reduceArgMin_0 is the mirror image of reduceArgMax_0: instead of finding where a row or column is brightest, it finds where it's darkest. Give it an image, it gives you back the index of the minimum value along one axis - a vector of integer positions, one per column or per row.

It comes from opencv-comfyui (geroldmeisinger/opencv-comfyui), which wraps OpenCV's standalone functions as auto-generated nodes. The practical pitch: any "find the empty strip" or "find the shadow" analysis. Run a mask through reduce_0 to get a per-row profile, then argmin to locate the darkest scanline - useful for detecting a black bar, a gap between objects, or where a background region starts. It's the same family of "locate the thing without a detector" plumbing as argmax, pointed at the other end of the histogram.

The inputs that matter

  • src - an NPARRAY from Image2Nparray. As with its sibling, grayscale is the sane input; argmin on raw BGR mostly reports channel noise.
  • axis - the scan direction. 0 gives you, per column, the row index of that column's minimum (output: a row of length = image width). 1 gives you, per row, the column index of that row's minimum (output: a column of length = image height).
  • lastIndex - tie-break: False returns the first occurrence of the min, True returns the last. With flat black regions, every pixel ties at zero and this flag decides which one you get.
  • dst - optional out-parameter; leave it unconnected.

Output is an nparray of integer indices. It is not an image, so Nparrays2Image is the wrong next stop - wire the indices into math or routing nodes 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 installed:

pip install opencv-contrib-python

Gotchas worth knowing

The axis convention will bite you once: axis=0 yields row indices, axis=1 yields column indices - exactly backwards from what intuition suggests. And tie handling matters more for min than max, because dark/black pixels tie constantly; if your result jumps around between runs, lastIndex is the lever. Otherwise it's the same pack-wide story: everything runs on NPARRAY (BGR, 0–255), so bridge in with Image2Nparray, do your math, and don't expect the index output to be a viewable frame.

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
srcNPARRAY
axisINT
lastIndexBOOLEAN
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY