Nodes/ComfyUI-BrainDead/BD Color Extract
ComfyUI Node

BD Color Extract

Extract pixels matching a target color from an image as a greyscale mask. Pulls out all pixels close to the target color (within tolerance) and outputs a mask where matching pixels are white. Use hue mode for color-identity matching (any shade of the color regardless of brightness — perfect for painted shadow extraction). Use rgb_distance for strict RGB triplet matching.

By BizaNator·Created 7 months ago·Updated 16 days ago· 14
BD Color Extract
  • image
  • mask
  • color_mask
  • mask
target_r0.00
target_g0.00
target_b1.00
match_modehue
tolerance0.15
min_saturation0.10
soft_edge0.050
gradient_modefalse
invertfalse
Category🧠BrainDead/Segmentation

Inputs (11)

NameTypeDefaultDescription
imageIMAGESource image to extract color from.
target_rFLOAT0.000–1Target color RED component (0-1). Default 0.0 (for blue).
target_gFLOAT0.000–1Target color GREEN component. Default 0.0 (for blue).
target_bFLOAT1.000–1Target color BLUE component. Default 1.0 (for blue).
match_modeCOMBOhuehue (default): matches by color identity in HSV. Brightness-independent — 'any blue' regardless of how dark/light. Best for painted color extraction. rgb_distance: strict RGB Euclidean distance match. Use when you want only pixels very close to a specific RGB triplet.
toleranceFLOAT0.150–1How loose the match is. In hue mode: tolerance in hue units (0.15 ≈ ±54° of hue). In rgb_distance mode: max distance in RGB space (0.15 ≈ pixels within 0.15 unit sphere of target). Lower = stricter.
min_saturationFLOAT0.100–1HUE MODE ONLY — pixels with saturation below this are ignored (treated as non-matching). Prevents greys/near-whites from accidentally matching the target hue when their hue calc is unreliable. Set to 0 to match desaturated pixels too. Ignored in rgb_distance mode.
soft_edgeFLOAT0.0500–0.5Smoothstep falloff around the tolerance boundary. 0 = hard binary cutoff. Larger = softer mask edge.
gradient_modeBOOLEANfalseWhen ON: output is a smooth gradient based on HOW CLOSE each pixel is to the target color. Pixel at target = 1.0, far pixel = 0.0, smooth fade. Ignores soft_edge. Use for 'how much blue tint does this pixel have' style extraction. OFF: thresholded binary-ish mask with soft_edge.
invertBOOLEANfalseInvert the output mask (1 - mask). Use to extract everything EXCEPT the target color.
maskoptMASKOptional region mask. When provided, output is zero outside this region (restricts extraction to e.g. skin areas).

Outputs (2)

NameTypeDescription
color_maskIMAGEGreyscale mask (3-channel image, R=G=B=mask_value). White where pixels match the target color, black elsewhere.
maskMASKSingle-channel MASK version for nodes expecting MASK type.