Nodes/ComfyDL/VOC Label Indices
ComfyUI Node

VOC Label Indices

VOC's color-coded masks, converted to class indices you can train on

By Cynthia-lxx·Created 2 months ago·Updated 2 days ago· 6
VOC Label Indices
  • colormap
  • colormap2label
  • label_mask

A PASCAL VOC label is a picture where the colors are the labels: pixels painted (128, 0, 0) mean aeroplane, (128, 128, 0) means bicycle, and so on. Models don't train on colors, they train on class indices - so something has to convert. VOC Label Indices is that converter: it takes a VOC colormap image plus the lookup table from VOC Colormap→Label, and returns a [H, W] mask where each pixel is its class number (0–20).

The mechanism is where the pack's design pays off. The input image comes in as a ComfyUI IMAGE ([B, H, W, C]), gets converted to [H, W, C], each pixel's RGB is packed into a single index - (R * 256 + G) * 256 + B - and then that index is looked up in the pre-built 256³ table. One vectorized indexing operation, and the whole image is class numbers. It's fast, and it's why the pack splits this into two nodes: the table is built once (VOC Colormap→Label), then reused across every image you convert.

Inputs

  • colormap - the VOC label image as a native ComfyUI IMAGE ([B, H, W, C]). It takes the first batch item, so feed one image at a time.
  • colormap2label - the lookup table tensor from VOC Colormap→Label. This is a hard requirement, not a nicety - without it there's nothing to look up against.

Output

One output: label_mask, a MASK. A [H, W] float tensor where each pixel's value is the class index - 0 for background up to 20 for tv/monitor. The MASK type is ComfyUI's own, which means unlike the pack's custom cdlTensor types, this one plays nicely with ComfyUI's native mask ecosystem - you can feed it to other mask-based nodes, not just ComfyDL ones. And when you want to know what class 15 is, that's where VOC Classes (CdlVocClasses) comes in.

Installing it

Part of ComfyDL. ComfyUI Manager, search "ComfyDL". Or:

cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL
pip install -r ./ComfyDL/requirements.txt

Restart ComfyUI. Only matplotlib to install, no model downloads.

Gotchas

Two things to keep straight. First, the colormap input must be a VOC-colored label image - a normal photo fed in here will produce garbage indices, because most of its RGB values aren't in the table and will look up to background (0). It converts labels, it doesn't segment images for you. Second, it takes the first batch item and silently ignores the rest - if you pass a batch of label images you'll only convert the first one, which is a classic "why is only one mask right" confusion. Keep the conversions one image at a time. Otherwise this is a thin, correct wrapper: table in, mask out, and because the output is native MASK it's one of the few ComfyDL outputs that interoperates with the wider ComfyUI ecosystem rather than living only inside the pack.

Categoryd2l/Segmentation

Inputs (2)

NameTypeDefaultDescription
colormapIMAGE
colormap2labelTENSOR

Outputs (1)

NameTypeDescription
label_maskMASK