Nodes/opencv-comfyui/OpenCV sortIdx_1
ComfyUI Node

OpenCV sortIdx_1

SortIdx_1 — the permutation node's duplicate twin

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV sortIdx_1
  • src
  • dst
  • nparray
flags

By now the pattern is almost comforting: sortIdx_1 is sortIdx_0 under a second auto-generated name. The pack parses cv2.sortIdx's (src, flags, dst) signature out of OpenCV's type stubs twice (the MatLike and UMat forms), numbers each, and ships both as nodes that call the identical function with identical arguments. There is no difference in behavior. The "1" is a serial number, not an upgrade.

If you landed here cold, the sortIdx_0 article has the real content - what a sort-permutation is, why you'd want indices instead of values, and how the flags bitmask works. This page is the duplicate's duplicate.

What it takes

  • src (NPARRAY) - the array to sort.
  • flags (INT) - bitmask: direction 0 ascending / 16 descending, axis 0 rows / 1 columns. Values 0, 1, 16, 17.
  • dst (NPARRAY, optional) - out-parameter; leave it unwired.

Output: an nparray of integer indices - same shape as src, each element the original position that lands in that sorted slot. Not a picture.

Why the indices version exists

sort_0 reorders values; sortIdx hands you the permutation. That's the output you want when you need to rank or reorder parallel data - take a score array, sort its indices, then apply that ordering to the array that actually carries the content. It's also the building block for masked or selective pixel sorting, where you compute one ordering and reuse it across several arrays. The index map is data, not pixels, so don't try to render it through Nparrays2Image - that's the README's documented 'NoneType' object has no attribute 'shape' trap.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python

or ComfyUI Manager → "opencv-comfyui". Restart. Deps: opencv-contrib-python, numpy, torch.

Troubleshooting

  • 'NoneType' object has no attribute 'shape' → an index array isn't an image; don't convert it as one.
  • Indices surprising you → check flags; ascending/descending and row/column bits are easy to flip.
  • Cannot import name 'guidedFilter' at startup → conflicting OpenCV packages; README links the fix.

One node, two names. If sortIdx_0 made sense, you've got everything this one offers.

Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
srcNPARRAY
flagsINT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY