ComfyUI Node
CV HFS Segmentation (hierarchical feature selection)
Segments an image into regions via hierarchical feature selection (cv2.hfs): SLIC superpixels are merged by texton + colour similarity over two gradient-threshold stages. Outputs a per-pixel region index map (uint16, one region label per pixel), a region-coloured version of the image (each region is repainted with its average colour), and the region count. Works without a GPU (CPU path). The merge thresholds trade region purity against region count: raise them to merge more aggressively, and lower 'spatial weight' to let colour/texture dominate over proximity.
CV HFS Segmentation (hierarchical feature selection)
- image
- segmented
- labels
- num_regions
◄egb_threshold_i0.08►
◄min_region_size_i100►
◄egb_threshold_ii0.28►
◄min_region_size_ii200►
◄spatial_weight0.60►
◄superpixel_size8►
◄slic_iterations5►
Categoryimage/CV/contrib
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | COMFY_MATCHTYPE_V3 | Full-colour image to segment (3 channels). The region index map has one label per pixel and the same height/width. 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. | |
| egb_threshold_iopt | FLOAT | 0.080–1 | Stage-I merge threshold: gradient below this and two regions merge. Higher = fewer, larger regions (and less detail kept). |
| min_region_size_iopt | INT | 1001–100000 | Stage-I minimum region size in pixels; regions smaller than this get absorbed into a neighbour. |
| egb_threshold_iiopt | FLOAT | 0.280–1 | Stage-II threshold, applied to the coarser regions. Usually comfortably larger than egb_threshold_i, hence the second coarser pass. |
| min_region_size_iiopt | INT | 2001–100000 | Stage-II minimum region size in pixels; the final merge removes regions smaller than this. |
| spatial_weightopt | FLOAT | 0.600–1 | Weight of spatial distance inside the SLIC clustering (0 = colour/texture only, 1 = pure proximity). The default already leans on colour. |
| superpixel_sizeopt | INT | 82–256 | SLIC superpixel size in pixels. Smaller = more seeds = finer detail captured; larger runs faster and over-merges small features. |
| slic_iterationsopt | INT | 51–50 | SLIC clustering iterations. 5 is plenty for convergence; raise to 10 on very textured content. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| segmented | COMFY_MATCHTYPE_V3 | The input with every region repainted by its average colour - a quick visual of the region map. |
| labels | NPARRAY | uint16 per-pixel region index (0..num_regions-1), the same height/width as the input. Feed this into mask/crop/Draw Nodes. |
| num_regions | INT | Number of distinct regions in the label map. |