OpenCV minMaxLoc_0
Find the darkest and brightest pixel in your image in one pass
- src
- mask
- float_0
- float_1
- literal_2
- literal_3
Need to know exactly where the brightest pixel of a mask or depth map is, and how bright it actually is? That's minMaxLoc_0 - a thin wrapper around cv2.minMaxLoc that scans an array once and hands you the minimum, the maximum, and both their pixel locations. No model, no API, no key. It's a measurement node, and it's one of the more genuinely useful ones in this pack.
Why you'd reach for it
The typical ComfyUI moment: your pipeline produced a mask, a depth map, a disparity map, or a heatmap-style array, and you have no idea what its value range actually is. Everything downstream (thresholding, normalizing, compositing) depends on that range. minMaxLoc_0 answers it in one run and also tells you where the extremes are - the brightest spot in a saliency map, the hole in a mask, the darkest shadow in a depth pass.
It pairs naturally with normalize_0: check the min/max here, then stretch the array to a known range there.
What it does
Feed it src (an NPARRAY) and it returns four things:
float_0- the minimum valuefloat_1- the maximum valueliteral_2- the min's locationliteral_3- the max's location
The mask input is optional: if you only care about a region, pass a mask and it limits the search. One caveat that catches everyone: src must be single-channel. A 3-channel RGB/BGR array throws error: (-215:Assertion failed) img.type() == CV_8UC1. Fix it with cvtColor (code=6, BGR2GRAY) before this node.
Also note the two location outputs come back as STRING literals, something like (42, 87), not as two separate floats. That's the auto-generation tax: Point is a composite type in OpenCV, and this pack hands composite types back as parseable strings. If you need the x/y as numbers, ast-parse the string or use an intermediate step.
Installing it
Part of geroldmeisinger/opencv-comfyui, a pack that auto-generates a node for ~635 top-level cv2 functions. Install via ComfyUI Manager (search "opencv-comfyui") or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
then restart. The only real dependency is OpenCV (opencv-contrib-python); most installs already have it via another node pack. If you see Cannot import name 'guidedFilter' from 'cv2.ximgproc', you have conflicting OpenCV installs - that's a known problem with a documented fix in the README.
The pipeline you need first
These nodes speak NPARRAY, not Comfy's IMAGE. Chain: IMAGE → Image2Nparray → minMaxLoc_0 → ... → Nparrays2Image → IMAGE. Image2Nparray flips RGB→BGR and only takes batch_size==1 (otherwise use ImageFromBatch with length=1). Nparrays2Image flips back for viewing.
Troubleshooting
img.type() == CV_8UC1- you fed a 3-channel array; grayscale it first withcvtColorcode 6.- Batch error -
Image2Nparrayonly accepts one image at a time; slice withImageFromBatch. - The float/literal outputs aren't images, so don't feed them into
Nparrays2Image- that's where'NoneType' object has no attribute 'shape'comes from.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| maskopt | NPARRAY | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| float_0 | FLOAT | — |
| float_1 | FLOAT | — |
| literal_2 | STRING | — |
| literal_3 | STRING | — |