Nodes/comfyui_cv/CV Superpixels
ComfyUI Node

CV Superpixels

Splits the image into perceptually uniform regions that respect edges (cv2.ximgproc). Superpixels are a much better unit than a pixel grid for region-wise recolouring, palette work, selective masking or cartoon flattening: each region is already colour- and edge-coherent. Outputs the label map (one integer per pixel) plus a contour mask of the region boundaries. Feed the image and the labels to 'CV Reduce Array By Label' (mean) for one colour per region, then paint it back with 'CV Take By Index' (the 'CV Superpixel Paint' subgraph blueprint does exactly that); or preview the labels with 'Preview CV Array' (normalize).

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Superpixels
  • image
  • labels
  • contours
  • count
algorithmSLICO
region_size20
num_superpixels200
iterations10
compactness10.0
enforce_connectivitytrue
Categoryimage/CV/contrib

Inputs (7)

NameTypeDefaultDescription
imageNPARRAY,IMAGEImage to segment (3-channel). Frame 0 of a batch. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
algorithmCOMBOSLICOSLIC needs an explicit compactness; SLICO (the default) tunes it per region; MSLIC adds manifold-aware sizing. LSC preserves fine structure best. SEEDS and ScanSegment take a TARGET COUNT instead of a region size and are the fastest.
region_sizeINT204–512SLIC/SLICO/MSLIC/LSC: average superpixel width in pixels - the region COUNT follows from the image size. Ignored by SEEDS/ScanSegment, which use num_superpixels instead.
num_superpixelsINT2002–10000SEEDS/ScanSegment: how many regions to aim for (approximate). Ignored by the others.
iterationsINT101–100Refinement passes. More = better-fitting boundaries, linearly slower; 4-10 is usually enough.
compactnessoptFLOAT10.00.1–100SLIC/MSLIC: how strongly regions are pulled towards a compact shape. High = tidy squarish blobs that cut across edges; low = ragged regions that hug edges. For LSC this is the 'ratio' (0-1); SLICO ignores it entirely.
enforce_connectivityoptBOOLEANtrueMerge stray disconnected fragments into their neighbours so every label is one connected region. Turn off only if you want the raw clustering.

Outputs (3)

NameTypeDescription
labelsNPARRAYint32 (H,W) map: the region index each pixel belongs to, from 0 to count-1.
contoursNPARRAYuint8 (H,W) mask, 255 on region boundaries - overlay it to see the segmentation.
countINTNumber of superpixels actually produced (may differ from the requested count).