ID Mask Extract
Click a color, get a region matte
- image
- mask
- image
- mask
- id_mask_info
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 settarget_r,target_g,target_bdirectly to the ID color. Precise and deterministic: same inputs, same mask, every run. This is the mode for stable, repeatable pipelines.sample_position- you setsample_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.
Inputs (15)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| selection_mode | COMBO | 2 options: manual_color, sample_position | |
| color_space | COMBO | 2 options: rgb, hsv | |
| target_r | FLOAT | 1.0000–1 | — |
| target_g | FLOAT | 0.0000–1 | — |
| target_b | FLOAT | 0.0000–1 | — |
| sample_x | FLOAT | 0.5000–1 | — |
| sample_y | FLOAT | 0.5000–1 | — |
| tolerance | FLOAT | 0.1200–1 | — |
| softness | FLOAT | 0.0400–0.5 | — |
| blur_radius | FLOAT | 0.00–64 | — |
| invert_values | BOOLEAN | false | — |
| mask_feather | FLOAT | 8.00–256 | — |
| invert_mask | BOOLEAN | false | — |
| maskopt | MASK | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| id_mask_info | STRING | — |