Nodes/comfyui-image-manipulation/Create Mask From Colors
ComfyUI Node

Create Mask From Colors

Pick a body part, get a mask — the DensePose color trick with a misleading name

By Hellfiredragon·Created 2 years ago·Updated 2 years ago· 0
Create Mask From Colors
  • image
  • MASK
face-leftFalse
face-rightFalse
torso-frontFalse
torso-backFalse
upper-left-arm-outsideFalse
upper-left-arm-insideFalse
upper-right-arm-outsideFalse
upper-right-arm-insideFalse
lower-left-arm-outsideFalse
lower-left-arm-insideFalse
lower-right-arm-outsideFalse
lower-right-arm-insideFalse
right-handFalse
left-handFalse
upper-left-leg-frontFalse
upper-left-leg-backFalse
upper-right-leg-frontFalse
upper-right-leg-backFalse
lower-left-leg-frontFalse
lower-left-leg-backFalse
lower-right-leg-frontFalse
lower-right-leg-backFalse
right-footFalse
left-footFalse
grow16
blur7

The name is a lie. Create Mask From Colors has no color picker, no hex fields, no tolerance slider. What it actually does is turn a DensePose body-part map into a mask for whichever body parts you toggle on. You feed it the rainbow-colored person image that comes out of a DensePose preprocessor - the one that paints the torso blue, the face yellow, each arm and leg its own shade - and it returns a white mask covering, say, just the torso, or just the hands, or the whole body.

That's a niche but genuinely handy trick. Pose-based ControlNet pipelines and body-aware workflows constantly want to mask part of a person for inpainting or regional prompting, and DensePose maps are one of the few inputs where that region is already precisely labeled per-pixel. This node reads those labels.

How it works

Under the hood the node keeps a hardcoded BODY_PARTS dict: 24 part names, one hex color each. That palette matches DensePose's classic 24-part segmentation - face-left, torso-front, upper-right-arm-outside, lower-left-leg-back, and so on, all the way down to left-foot. For every part you toggle on, it grabs that part's hex color and selects every pixel whose RGB matches it exactly (diff <= 0 - tolerance is zero, hardcoded). Selected parts get OR'd together into one white mask.

Then two post-steps soften it up: grow (binary dilation, default 16) expands the mask outward, and blur (gaussian, default 7) feathers the edges. Both use kornia under the hood - which ComfyUI bundles with core, so it normally just works. If you ever hit an ImportError on kornia in a bare venv, pip install kornia fixes it.

Inputs that matter

  • image (IMAGE) - the DensePose-colored input. It must use the exact palette the node expects; this is non-negotiable.
  • The 24 body-part toggles - all default to False. Toggle nothing and you get an all-black, empty mask, which is the most common "it's broken" moment. Turn on only what you want.
  • grow (default 16) and blur (default 7) - the smoothing pair. A default grow of 16 is a lot of expansion; it fills holes but balloons the region. Set both to 0 for a strict, hard-edged exact selection.

Output is a single MASK, ready to wire into Inpaint, a mask-to-image blender, or whatever region node you're using.

Gotchas

  • Exact match only, no tolerance. This is the real limitation. Any JPEG compression, resizing, or anti-aliasing shifts colors and leaves speckles or holes in the mask. Feed it a clean PNG straight out of the DensePose preprocessor - don't re-encode, don't screenshot it.
  • Right input, wrong colors. If you fed a normal render instead of an actual DensePose map, nothing will match and you'll get an empty mask. Check that the person in your input is actually painted in the palette colors.
  • Grow before blur. The expansion happens first, which is why default edges still look okay; if you crank grow way up the mask can bleed past the silhouette. Drop it if you're doing something precise like clothing-only inpainting.

Installing it

Same pack as its sibling: comfyui-image-manipulation from Hellfiredragon. ComfyUI Manager (search the pack title) or:

cd ComfyUI/custom_nodes
git clone https://github.com/Hellfiredragon/comfyui-image-manipulation

Restart after. Deps are just pillow, numpy and torch - no models, no downloads. It's a small, single-purpose pack, and this node is the more interesting half of it.

CategoryIM Pack

Inputs (27)

NameTypeDefaultDescription
imageIMAGE
face-leftBOOLEANFalse
face-rightBOOLEANFalse
torso-frontBOOLEANFalse
torso-backBOOLEANFalse
upper-left-arm-outsideBOOLEANFalse
upper-left-arm-insideBOOLEANFalse
upper-right-arm-outsideBOOLEANFalse
upper-right-arm-insideBOOLEANFalse
lower-left-arm-outsideBOOLEANFalse
lower-left-arm-insideBOOLEANFalse
lower-right-arm-outsideBOOLEANFalse
lower-right-arm-insideBOOLEANFalse
right-handBOOLEANFalse
left-handBOOLEANFalse
upper-left-leg-frontBOOLEANFalse
upper-left-leg-backBOOLEANFalse
upper-right-leg-frontBOOLEANFalse
upper-right-leg-backBOOLEANFalse
lower-left-leg-frontBOOLEANFalse
lower-left-leg-backBOOLEANFalse
lower-right-leg-frontBOOLEANFalse
lower-right-leg-backBOOLEANFalse
right-footBOOLEANFalse
left-footBOOLEANFalse
growINT160–8096
blurINT70–8096

Outputs (1)

NameTypeDescription
MASKMASK