Color Mask To Depth Mask (Inspire)
Assign depth values to painted color regions
- color_mask
- MASK
This one's a little different from a plain masking node. Instead of producing an on/off mask, it builds a graded mask where each painted color region carries its own value between 0.0 and 1.0. You paint a color map, then write a short spec that says "red means 1.0, black means 0.0," and it flattens that into a single mask where different areas hold different strengths. Think of it as hand-authoring a crude depth map (or any per-region value map) out of flat colors and a text spec.
Where it pays off: regional control where you want degrees, not just regions. A depth-style mask for conditioning. A per-area strength map. Anywhere a simple binary mask is too blunt and you want "strongly here, gently there, nothing over there" in one output.
How it works
You give it the color map and a spec - a little text list pairing hex colors with values, one per line, like the default #FF0000:1.0 / #000000:1.0. Each color becomes a layer with its stated value. Those layers get flattened together into one final mask, and the flatten_method decides how overlapping or stacked layers combine. There's a base value for the untouched background, and a dilation control to grow or shrink each layer's coverage before flattening. The output values are clamped to the 0.0–1.0 range.
The inputs and outputs that matter
color_mask(IMAGE) - the flat-color image the regions are read from.spec(multiline text) - the heart of it. Each line is#HEXCOLOR:value, e.g.#FF0000:1.0for red at full strength and#000000:0.0for black at zero. This is where you assign the actual depth/strength numbers to your colors.base_value(default 0) - the value the base/background layer holds, i.e. everything not covered by a spec'd color.flatten_method(override/sum/max) - how the layers merge.override: upper layer's non-zero pixels win.sum: values add up.max: each pixel takes the highest value across layers. Pick based on whether your regions should replace, accumulate, or take-the-strongest.dilation(default 0) - grows (positive) or shrinks (negative) each mask layer before flattening, handy for closing gaps between regions or pulling them apart.
The single output is MASK - the flattened, graded mask ready to feed depth-style conditioning, regional strength control, or anything that reads a soft mask.
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
A color in my image isn't showing up in the mask. It has to be listed in the spec. Colors not named in the spec fall back to base_value. Double-check the hex is exact - #FF0000 won't match a slightly-off #FE0101 from a soft brush or JPEG compression. Paint hard-edged and save PNG.
The values look wrong where regions overlap. That's flatten_method. If two spec'd regions touch or stack, sum will add them (possibly clamping to 1.0), max takes the higher, override lets the top layer win. Switch methods until the overlap behaves how you want.
Seams or gaps between regions. Use dilation - a small positive value grows each layer to close hairline gaps; a negative value shrinks them apart if they're merging.
Everything comes out one flat value. Your spec probably assigns the same number to every color, or only one color is present. The whole point is different values per color, so give each its own number in the spec.
I just want plain on/off masks. Then this is overkill - use Color Map To Masks instead, which gives you binary masks per color without the value grading.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| color_mask | IMAGE | — | |
| spec | STRING | #FF0000:1.0 #000000:1.0 | — |
| base_value | FLOAT | 0.000–1 | — |
| dilation | INT | 0-512–512 | — |
| flatten_method | COMBO | 3 options: override, sum, max |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |