Color Map To Masks (Inspire)
Turn a flat-color image into a batch of masks
- color_map
- MASK
Painting a bunch of separate black-and-white masks is tedious. Painting one image with flat color blobs - red here, green there, blue over there - is easy, and you can do it in any paint app in thirty seconds. This node takes that single color-coded image and cracks it into a set of individual masks, one per color. It's the mask-factory behind color-driven regional workflows.
The idea comes straight from how Inspire handles regional prompting by color: instead of managing N masks, you manage one color map. This node is the general-purpose version that hands you back the actual masks, so you can wire them into anything that wants a MASK - regional conditioning, IP-Adapter regions, inpainting, compositing, whatever.
How it works
It scans the color map, finds the distinct colors present, ranks them by how many pixels they cover, and generates a mask for each of the top ones. A color has to occupy at least a minimum number of pixels to count, which filters out anti-aliasing fringes and stray specks so you don't get a dozen junk masks from color bleed at the edges. The result is a mask batch - the masks come out in order, most-prominent color first.
The inputs and outputs that matter
color_map(IMAGE) - your flat-color image. Hard-edged fills work best; keep it lossless.max_count(default 5) - how many masks to produce, i.e. the top N colors by area. If you painted four regions, 4 or 5 is right. Bump it up if you've got more regions.min_pixels(default 500) - the floor for a color to qualify. Colors covering fewer pixels than this are ignored. Raise it to be stricter about ignoring small stray areas; lower it if a genuinely small region is getting dropped.
The single output is MASK - a batch, one mask per detected color. Downstream you typically split or index into it (e.g. with a Select Nth Mask node) to grab the specific region you want, or feed the whole batch into something that iterates masks.
How to install it
ComfyUI Manager: search ComfyUI Inspire Pack, install, restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Inspire-Pack
then restart. Dr.Lt.Data's pack (ComfyUI-Manager, Impact Pack).
Common issues & troubleshooting
Too many masks, including garbage ones. Anti-aliased edges and JPEG artifacts create thousands of near-colors, and some sneak past the filter. Two fixes: paint with hard-edged flat fills (no soft brushes, no gradients) and save as PNG, and raise min_pixels so small speckled regions don't qualify.
A region I painted is missing. Either it's smaller than min_pixels (lower the threshold) or it fell outside the top max_count colors (raise the count). If two regions are almost the same color, they may be merging into one mask - make your colors distinctly different.
The mask order isn't what I expected. Masks come out ranked by pixel count, biggest region first - not by hue or by where you painted them. If you need a specific region reliably, either make each region a clearly different size, or use a color-specific node instead where you name the exact color.
Colors don't match what I painted. Saving as JPEG shifts colors. So does any tool that applies color management on export. Use PNG and check your export isn't re-encoding the palette.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| color_map | IMAGE | — | |
| min_pixels | INT | 5001–18446744073709550000 | — |
| max_count | INT | 50–1000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |