Nodes/ComfyUI-WJNodes/color segmentation
ComfyUI Node

color segmentation

Turn an ADE20K-style color-block image into a usable mask

By 807502278·Created 2 years ago·Updated 11 months ago· 20
color segmentation
  • image
  • Color_list
  • select_mask
  • mask
select_batch0
skip_threshold0.050
merge_maskfalse
invert_maskfalse
invert_select_maskfalse
invert_selectfalse

If you've run a segmentation ControlNet preprocessor, you've seen the output: instead of grayscale or edges, you get a flat, cartoonish image where every object class - sky, wall, person, floor - is rendered as its own solid color, following a fixed palette like ADE20K's roughly 150 categories, or SAM2's own labeling. That "color block" image is useful for conditioning a ControlNet, but it's not directly usable as a mask. color segmentation bridges the two: point it at a color-block image and it turns specific colors into a binary mask you can actually use for inpainting, compositing, or region selection.

The inputs and outputs that matter

It needs a Color_list input to know which colors mean what - that comes from the sibling load_color_config node elsewhere in this pack, which loads the ADE20K (or SAM2) palette definitions. Feed the segmentation image into image, the palette into Color_list, and the node scans for matches. select_batch picks which frame to act on if you're working through a batch one at a time; skip_threshold (default 0.05) ignores color regions covering less than that fraction of the frame, filtering out compression noise and stray pixels that technically match a palette color but aren't a real region. merge_mask collapses every matched color into one combined mask instead of keeping them separate; invert_mask flips the final result.

There's a second, independent way to narrow things down: select_mask (optional) plus invert_select_mask and invert_select. Feed in your own mask - hand-drawn, from a depth map, whatever - and the node only counts segmentation hits that fall inside (or outside, with the invert flags) that region. Genuinely handy when the color-block image has multiple instances of the same class and you only want the one in a particular part of the frame.

Installing it

Same pack, same steps as every other WJNode node. ComfyUI Manager: search "ComfyUI-WJNodes," or:

cd ComfyUI/custom_nodes
git clone https://github.com/807502278/ComfyUI-WJNodes.git

Restart, find it under WJNode → ImageEdit → Color. No models to download for this node itself - the palette data comes from load_color_config, which reads config files bundled with the pack rather than downloading anything.

Where people get burned

The number one thing to get right is upstream of this node entirely: you need an actual segmentation-style color-block image feeding in, not a regular photo or a depth map - run it through a segmentation preprocessor (ADE20K-style, or SAM2's output) first. Without load_color_config wired into Color_list, the node has no idea which colors mean what, so double-check that connection before assuming the mask output is wrong. If your output mask looks emptier than expected, skip_threshold is worth tuning down - a busy image with lots of small, scattered matches for a color can get entirely filtered out at the 0.05 default if no individual region clears that coverage bar on its own.

CategoryWJNode/ImageEdit/Color

Inputs (9)

NameTypeDefaultDescription
imageIMAGE
select_batchINT00–999999
skip_thresholdFLOAT0.0500–1
Color_listLIST
merge_maskBOOLEANfalse
invert_maskBOOLEANfalse
select_maskoptMASK
invert_select_maskoptBOOLEANfalse
invert_selectoptBOOLEANfalse

Outputs (1)

NameTypeDescription
maskMASK