ID Map Quantize
Clean, indexed mattes from a messy ID pass
- image
- mask
- image
- mask
- id_map_info
ID maps - where every object or material gets its own flat color - are how tech artists and compositors select regions fast. The problem is that AI-generated "ID" passes are never clean: the seams bleed, the colors drift, and every boundary has a soft gradient that turns your clean selection into a feather you didn't ask for. ID Map Quantize is the MKRShift node that takes a messy ID map and snap-quantizes it into a fixed number of discrete, indexed colors - turning a noisy pass into proper, selectable flat regions.
It sits in MKRShift Nodes/Surface/Tech Art, the pack's lane for material/texture pipeline helpers. Where x1IDMaskExtract pulls one region out as a mask, this node cleans up the whole map at once, so every region becomes an individually usable selection.
How it works
The node takes your image and reduces it to levels distinct colors (2–16, default 4) by quantizing each channel's value into a small set of bins - in rgb space directly, or hsv if you want the reduction to respect hue/saturation/value relationships (usually the better choice for ID maps, since IDs are meant to be hue-separated). palette_mode then decides what those quantized colors become:
id_vivid- high-contrast, distinct palette colors, ideal for separating regions at a glance.id_pastel- lighter, gentler colors, friendlier on the eyes when you're staring at it for an hour.preserve- keeps the original hue family of each region, just flattened to fewer levels.
smoothing pre-blurs the map before quantization (kills noise speckles that would otherwise become their own ID), and edge_softness softens the boundaries afterward so selections aren't razor-hard if you're feeding a matte with soft edges downstream.
Outputs and wiring
You get the quantized image, a mask (the full quantization as a grayscale matte - each ID becomes a distinct gray step, which is exactly what a material-index node wants), and an id_map_info string reporting the resolved levels and palette. The optional mask input scopes the quantization to a region if you only need part of the map cleaned.
Wiring tip: this is a classic "cleanup before selection" node. Chain it into the pack's x1IDMaskExtract and you get much sharper, more stable per-region masks than you would from the raw pass - quantization first kills the gradient bleed that makes tolerance-based extraction so fiddly.
Installing it
cd ComfyUI/custom_nodes
git clone https://github.com/criskb/MKRShift_Nodes
then restart, or search MKRShift_Nodes in ComfyUI Manager. No models, no pip requirements - this is pure numpy indexing.
The main trap is picking levels too high: an AI ID pass has hundreds of unique colors, and if you ask for 16 you'll still get sub-regions that look split. Work from the few IDs you actually need (2–6) and use preserve mode when the original palette matters. And if regions keep merging, raise levels before you touch anything else - that's the cause 90% of the time.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| color_space | COMBO | 2 options: rgb, hsv | |
| levels | INT | 42–16 | — |
| palette_mode | COMBO | 3 options: id_vivid, id_pastel, preserve | |
| smoothing | FLOAT | 0.00–64 | — |
| edge_softness | FLOAT | 0.50–32 | — |
| mask_feather | FLOAT | 8.00–256 | — |
| invert_mask | BOOLEAN | false | — |
| maskopt | MASK | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| id_map_info | STRING | — |