ComfyUI Node
CV Reduce Array By Label
Collapses an array to ONE row per label: the mean, sum, min, max or median of every element carrying that label. The classic use is a region palette - feed an image plus the label map of 'CV Superpixels' (or watershed, connected components, HFS, k-means) and get the average colour of each region, then paint it back with 'CV Take By Index' for a flat, non-photorealistic render. Rows are indexed BY LABEL VALUE (row i = label i), which is what makes that round trip work; empty labels get 'empty_value'. For per-POINT attributes with circular or densest-window statistics use 'CV Reduce Values By Label' instead.
CV Reduce Array By Label
- values
- labels
- mask
- table
- counts
- count
◄reductionmean►
◄num_labels0►
◄empty_value0.00►
Categoryimage/CV/low-level
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| values | NPARRAY | Array to reduce: (N,), (N,C), [H,W] or [H,W,C]. Its leading axes must match 'labels' - the trailing axis is the channel axis and is reduced independently. | |
| labels | NPARRAY | Integer label per element: (N,) or [H,W], matching the leading axes of 'values'. NEGATIVE labels are excluded (watershed writes -1 on boundaries). | |
| reduction | COMBO | mean | How the members of each label are collapsed. mean is the region average (the palette case); median is the robust version when a region straddles an edge; sum with an all-ones input counts members (the 'counts' output does that for you). |
| num_labelsopt | INT | 00–2147483647 | Number of rows K to emit. 0 = derive it from the largest label present. Wire the 'count' output of 'CV Superpixels' here to pin the table height even when a region ends up empty; labels >= K are then ignored. |
| empty_valueopt | FLOAT | 0.00-1000000000000–1000000000000 | Value written for labels with no members (and for every row when the input is empty). 0 paints such a region black. |
| maskopt | NPARRAY | Optional inclusion mask, same shape as 'labels': nonzero elements take part in the reduction, zeros are ignored (e.g. drop the sky before averaging). |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| table | NPARRAY | (K,C) float32, row i = the reduction over label i. Always 2-D, so a single-channel input gives (K,1). Feed it to 'CV Take By Index' with the same label map to paint the result back over the image. |
| counts | NPARRAY | (K,) int32: how many elements carried each label. 0 marks a row that is 'empty_value', not a measurement. |
| count | INT | K, the number of rows in the table. |