DY Image Masks
One hard mask per palette color — the payoff of this pack
- image
- palette
- IMAGE_LIST
DY Image Masks is where the pack's whole gimmick pays off. Feed it an image and a palette, and it slices the image into a separate mask for every color in that palette - one mask where the sky is, another where the hair is, another for the wall. If you've ever wanted to decompose an image into "layers by color," this is that, done exactly literally.
The pipeline it completes: DYImageQuantize reduces your render to a handful of flat colors, DYImagePalette reads those exact colors out as a sorted list, and this node turns each color into its own white-on-black mask. Quantize → Palette → Masks is the pack's signature workflow, and it's genuinely neat: you get clean, stable, per-region masks out of a generated image without any segmentation model. That's a big deal when you want to recolour, replace, or composite individual parts of a render - think cheap, deterministic "select by color" on images that already have flat color regions.
How it works
The mechanism is brutally simple, which is both the strength and the weakness. For every color in the palette, it walks every pixel of the image and marks it 255 if it exactly equals that color, else 0, building a single-channel grayscale mask. Exact equality - no tolerance, no feathering. That's why the quantize step matters so much: with a few flat colors, exact matching works perfectly; with a photo's millions of colors, no pixel would ever match.
Two things to know about the output. First, it's IMAGE_LIST - a list of masks, one per palette color, in the same frequency order the palette was built in (so the biggest mask comes first). Second, like the COLOR_PALETTE type, IMAGE_LIST is a pack-internal type; the one node in this pack that eats it is ImageListToGrid, which turns the whole list into a single contact-sheet grid so you can see all your masks at once.
The masks come back as hard 0/255 binary masks. There's no blur or anti-aliasing knob - if you need soft edges, pass them through a core ComfyUI mask-blur node afterwards.
Inputs
- image - the quantized image (feed the same quantized image you made the palette from).
- palette - the
COLOR_PALETTEoutput from DYImagePalette.
Both are required, and you genuinely want them from the same run: the masks match the image's colors exactly, and any mismatch between the two means empty masks.
Install
Part of dymokomi/comfyui_dygen by Dy Mokomi. ComfyUI Manager → search "comfyui_dygen", or:
cd ComfyUI/custom_nodes
git clone https://github.com/dymokomi/comfyui_dygen
Restart. No extra deps, no models.
Troubleshooting
- All masks empty - the palette and image don't share exact colors. Re-quantize with the same settings, or just rewire Palette's output directly into this node.
- Slow on big images - it's an O(pixels × colors) double loop in Python. More palette colors or a bigger image means a longer wait. Keep
colorsmodest (16–64) and it's fine. - Masks look blocky/noisy - that's hard color selection; pair with a mask blur before use.
If you came for the pack's one genuinely clever idea, this is it - and it's small, predictable, and does exactly what it says on the tin.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| palette | COLOR_PALETTE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE_LIST | IMAGE_LIST | — |