Nodes/ComfyUI-TextureAlchemy/Custom Color to Mask
ComfyUI Node

Custom Color to Mask

Click a Color, Get a Mask

By amtarr·Created 9 months ago·Updated 4 months ago· 58
Custom Color to Mask
  • image
  • mask
color#FF0000
tolerance0.20
feather0.10
modergb

Selecting "all the red pixels" by hand is miserable. Custom Color to Mask is the magic-wand equivalent inside TextureAlchemy: you tell it a hex color, it finds every pixel close to that color, and hands you a proper ComfyUI MASK - the kind you can plug into inpaint, blend, and compositing nodes without a conversion step.

It's one of two color-to-mask nodes in this pack (the sibling Color Selection Mask outputs an IMAGE instead), and it's the one you want when a node downstream is picky about getting a real MASK tensor. For a texture pipeline that's more common than you'd think: isolating the dirt from an albedo so you can wear-map it, pulling the grout out of a tile texture, or building the selection that tells a wear generator where to work.

How it works

The node computes, per pixel, how far the color is from your target, and thresholds that distance by tolerance to decide what's in and what's out. The mode dropdown picks how "distance" is measured:

  • rgb - Euclidean distance in RGB space. Simple, works for most flat-color stuff.
  • hsv - distance in hue/saturation/value space. Better when lighting varies, because it cares less about brightness. This is the one for shadows-and-highlights situations.
  • luminance - brightness-based matching. Good for isolating a brightness range rather than a hue.

feather then softens the mask edge by that fraction of the image, so you don't get a hard aliased boundary.

The inputs that matter

  • image - your texture.
  • color - hex string (#RRGGBB). The node's widget includes a 🎨 picker and a 💧 eyedropper so you can click directly on the image instead of guessing hex values. Use the eyedropper; guessing hex for "that exact red" is a fool's errand.
  • tolerance (0–1, default 0.2) - raise it if the color you want is a range (skin tones, weathered metal) rather than a single flat hue.
  • feather (0–0.5, default 0.1) - edge softness.
  • mode - rgb / hsv / luminance as above.

Output is a single mask of type MASK, ready for any mask-consuming node in ComfyUI.

Where it slots in

A classic TextureAlchemy move: extract a PBR set, run the albedo through this node to grab the red accent color as a mask, then use that mask to drive a wear or color-change effect only on the red bits. Or use it to select a color range from a height map so only the raised areas get detailed. It's selection, generalized.

Installing it

It ships inside TextureAlchemy:

cd ComfyUI/custom_nodes
git clone https://github.com/amtarr/ComfyUI-TextureAlchemy

restart, and look under Texture Alchemist → Masks. ComfyUI Manager: search "Texture Alchemy". No extra pip dependencies.

Gotchas

The trap is expecting tolerance to behave like Photoshop's fuzziness - it's normalized 0–1 here, so "a bit" is like 0.1–0.3, not 30. And remember the output type: if you plug this into a node that wants an IMAGE and you're getting type errors, that's not a bug, that's a MASK doing its job - use Color Selection Mask instead, or convert with ComfyUI's Mask to Image node.

CategoryTexture Alchemist/Masks

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
colorSTRING#FF0000Target color in hex (#RRGGBB). Use 🎨 Pick Color or 💧 Eyedropper below to select.
toleranceFLOAT0.200–1Color matching tolerance
featherFLOAT0.100–0.5Edge softness
modeCOMBOrgbColor distance mode

Outputs (1)

NameTypeDescription
maskMASK