Multi Color Mask (DAELab)
Mask by color, with sixteen slots and one output
- images
- mask
Flat-design workflows are basically a colour-selection problem wearing a disguise. You have a badge or a poster with eight flat colour blocks, and you need a mask per block. The usual answer is eight colour-threshold masks chained with combines, which is unmaintainable the moment someone changes the artwork.
Multi Color Mask (DAELab) collapses that into one node: a dynamic list of colour-matching groups, one MASK output, and a selector that lets you choose which group's mask comes out - or the union of all of them.
The mechanism
Two inputs: images (an IMAGE batch) and config_json (a string that holds the whole group list). The front end owns config_json; you edit it through the node's UI, and it's serialised into the workflow like any other widget value.
For each enabled group the node parses its colour, computes the per-pixel distance from your image in RGB as an L2 norm, and thresholds it at threshold / 255. Optionally inverted. That's it - no perceptual space, no dithering, just straight Euclidean RGB, which is exactly what you want for flat artwork where the block colours are genuinely distinct.
The output selector then resolves to either mask_N (that single group, disabled groups come out black) or combined_mask, which is the elementwise max of all enabled groups. Max, not sum - so overlapping selections still produce a valid 0..1 mask rather than clipping.
One detail that matters more than it sounds: IS_CHANGED deliberately ignores images and hashes the resolved config instead. That means changing a colour or a threshold invalidates the cache properly, which is why iterating on thresholds feels instant instead of re-running half your graph.
It also accepts pixel values either in 0–1 or 0–255 and normalises internally, so a float image that came out of an unexpected place doesn't silently produce an all-black mask. Values outside both ranges raise a clear error instead.
Reading the config, casually
You don't need to hand-write config_json, but knowing its shape helps when a workflow misbehaves:
{"output": "combined_mask",
"groups": [{"color": "#FF1744", "threshold": 24, "invert": false, "enabled": true}]}
Groups are positional - mask_1 is the first entry. That's why reordering groups silently reassigns which mask comes out, and why the V1 node in this same pack puts so much effort into keeping the selection stable when you insert or delete.
Outputs and where they go
One output: mask. Wire it into an inpaint, a Set Latent Noise Mask, a colour-to-mask consumer, a height-layer node, anywhere a MASK is expected.
Because there's a single output port, the switching happens inside the node rather than by re-wiring. That's a deliberate ergonomic choice: one node per artwork, and you change which region you're editing by changing a dropdown. If you'd rather see all masks simultaneously, run several of these nodes instead - the graph stays legible and ComfyUI caches them independently.
In a badge pipeline this is the node that turns "the red ring" or "the blue enamel field" into an actual mask without any drawing. Combine it with a foreground mask (a multiply or a mask composite) and you get region-accurate, artwork-accurate selections for free.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/TeutonicMepheles/ComfyUI-DAELab-Custom-Nodes-Library.git
Restart ComfyUI and refresh the browser tab - the group editor is a web/ front-end module, so a stale tab shows the node with an uneditable config_json and no way in. In ComfyUI Manager, search the pack title. Node IDs in this pack are kept stable on purpose, so updates won't break saved workflows; do not install a second, older copy of the same node folder alongside it, or you'll get duplicate-ID errors at startup.
Gotchas
Set the threshold from the artwork, not from intuition. Antialiased edges between two blocks sit between both colours, so a tight threshold (4–8) gives you a hard medial-edge mask; a loose one (30+) bleeds across adjacent blocks. Start at 16 and look at the result.
The invert flag is per group and it's easy to forget you left it on. An all-white mask is the classic symptom.
This node eats colour similarity, so it can't help with two regions that are the same colour - a chrome highlight and a silver plate will always be one mask. That's not a bug, it's the reason the pack also ships a polygon/brush editor. Use colour where colour separates, draw where it doesn't.
Finally: combined_mask is a union, which is great for "everything I want to change" and wrong for "the boundary between two things." If you need disjoint regions for separate paid edits, output one group per node.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| config_json | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |