Nodes/MKRShift_Nodes/ID Mask Extract
ComfyUI Node

ID Mask Extract

Click a color, get a region matte

By criskb·Created 7 months ago·Updated 5 months ago· 0
ID Mask Extract
  • image
  • mask
  • image
  • mask
  • id_mask_info
selection_mode
color_space
target_r1.000
target_g0.000
target_b0.000
sample_x0.500
sample_y0.500
tolerance0.120
softness0.040
blur_radius0.0
invert_valuesfalse
mask_feather8.0
invert_maskfalse

This is the node that turns an ID map into the one mask you actually need - no manual painting, no SAM click-and-hope. Feed it an ID/segmentation pass, tell it which color is the region you care about (or just point at a spot in the image), and it hands you a clean, feathered mask of that region. It's the selection half of the tech-art pair that x1IDMapQuantize starts: quantize first for clean IDs, then extract the specific region you're compositing or texturing.

It's in MKRShift Nodes/Surface/Tech Art, and its real-world use is broader than "material IDs from a 3D pass." Any segmentation map - an AI-generated instance segmentation, a colormap from a segmentation model - becomes one color per object, and this node lets you pull any one of those objects out as a mask without touching the others.

How it works

Two selection modes:

  • manual_color - you set target_r, target_g, target_b directly to the ID color. Precise and deterministic: same inputs, same mask, every run. This is the mode for stable, repeatable pipelines.
  • sample_position - you set sample_x/sample_y (0–1 normalized) and the node reads the color at that point in the image. Faster to set up, and it survives re-renders where the ID palette shifts but the layout doesn't. This is your "click on it" mode.

Either way the selection is made in color_space (rgb or hsv - hsv is often better when the ID colors are close together in value but differ in hue). tolerance (default 0.12) decides how close a pixel must be to the target to be included, and softness (0.04) feathers the color distance boundary so you get soft edges instead of a hard snap. blur_radius cleans up speckle noise, and invert_values flips the mask if you want everything except the region.

The workflow

Wire the ID map in, pick the mode, set tolerance low and raise it until the region just connects - then add softness so the edge isn't pixel-crisp. The mask output is the thing to wire into whatever you're doing next (a compositor, an inpaint, a material slot); image is the extraction visualized, and id_mask_info reports what it selected. The optional mask input scopes the whole operation.

For best results, run your ID map through x1IDMapQuantize first - a quantized map has flat, consistent colors, which makes tolerance behave predictably instead of chasing gradients.

Installing it

cd ComfyUI/custom_nodes
git clone https://github.com/criskb/MKRShift_Nodes

then restart, or install via ComfyUI Manager by searching MKRShift_Nodes. No models, no pip requirements.

The failure mode everyone hits: tolerance too high. A 0.5 tolerance on a noisy pass selects half the image, because gradient pixels count as "close." Start at 0.05–0.1 and creep up - the mask output makes it instantly visible whether you overshot. And when adjacent IDs are nearly the same color, switch to hsv color space; separating by hue fixes most "it grabbed the wrong region" moments.

CategoryMKRShift Nodes/Surface/Tech Art

Inputs (15)

NameTypeDefaultDescription
imageIMAGE
selection_modeCOMBO2 options: manual_color, sample_position
color_spaceCOMBO2 options: rgb, hsv
target_rFLOAT1.0000–1
target_gFLOAT0.0000–1
target_bFLOAT0.0000–1
sample_xFLOAT0.5000–1
sample_yFLOAT0.5000–1
toleranceFLOAT0.1200–1
softnessFLOAT0.0400–0.5
blur_radiusFLOAT0.00–64
invert_valuesBOOLEANfalse
mask_featherFLOAT8.00–256
invert_maskBOOLEANfalse
maskoptMASK

Outputs (3)

NameTypeDescription
imageIMAGE
maskMASK
id_mask_infoSTRING