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).
CV Superpixels
- image
- labels
- contours
- count
◄algorithmSLICO►
◄region_size20►
◄num_superpixels200►
◄iterations10►
◄compactness10.0►
◄enforce_connectivitytrue►
Categoryimage/CV/contrib
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| image | NPARRAY,IMAGE | Image 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. | |
| algorithm | COMBO | SLICO | SLIC 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_size | INT | 204–512 | SLIC/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_superpixels | INT | 2002–10000 | SEEDS/ScanSegment: how many regions to aim for (approximate). Ignored by the others. |
| iterations | INT | 101–100 | Refinement passes. More = better-fitting boundaries, linearly slower; 4-10 is usually enough. |
| compactnessopt | FLOAT | 10.00.1–100 | SLIC/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_connectivityopt | BOOLEAN | true | Merge stray disconnected fragments into their neighbours so every label is one connected region. Turn off only if you want the raw clustering. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| labels | NPARRAY | int32 (H,W) map: the region index each pixel belongs to, from 0 to count-1. |
| contours | NPARRAY | uint8 (H,W) mask, 255 on region boundaries - overlay it to see the segmentation. |
| count | INT | Number of superpixels actually produced (may differ from the requested count). |