π§ Mask From Segmentation
Turning a flat-color segmentation map into usable masks
- image
- MASK
If you've got an image where distinct regions are already flat, distinct colors - the output of a semantic segmentation model, one of ControlNet's segmentation preprocessor maps, or a mask sheet you hand-painted in flat color fills - Mask From Segmentation pulls those regions apart into clean, usable masks instead of you eyeballing hex values and building masks by hand.
This is not a segmentation model itself. It doesn't look at a photo and figure out where the person or the car is. It assumes the segmenting already happened and someone (or something) handed it an image where "region" already means "block of one flat color."
How it works
The node clusters the image's colors into segments buckets (1β16, default 6) and turns each cluster into its own region. From there, two cleanup passes and one fill option shape the result: remove_isolated_pixels (0β32) strips small stray pixels that don't belong to a real region - the kind of noise antialiasing or compression leaves along a segmentation map's edges. remove_small_masks (0β1, a fraction of total image area) drops whole masks that are too tiny to be a genuine segment rather than noise. fill_holes (default false) patches interior gaps so each resulting mask is one solid blob instead of swiss cheese.
Inputs and outputs
Required: image, segments, remove_isolated_pixels, remove_small_masks, fill_holes. Output: MASK.
Installing it
Via ComfyUI Manager, search "ComfyUI Essentials". Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/cubiq/ComfyUI_essentials
Restart. The pack has been in maintenance-only mode since April 2025.
Common issues & troubleshooting
Results look nothing like your source image's regions. Check what you're actually feeding it first - this only works cleanly on input that's already flat and segmented. Point it at a normal photo and segments will just cluster by dominant color, which produces something that looks plausible but isn't a real segmentation.
A region you wanted got merged into another one, or disappeared. segments is probably set lower than the actual number of distinct colors in your source map. Bump it up to match.
Small real regions vanish. remove_small_masks is likely too aggressive for your image. Start it at 0 and only raise it once you've confirmed you're fighting genuine noise, not real content.
Masks have unwanted holes in them. Turn on fill_holes - it's off by default, which surprises people expecting solid regions out of the box.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | β | |
| segments | INT | 61β16 | β |
| remove_isolated_pixels | INT | 00β32 | β |
| remove_small_masks | FLOAT | 0.000β1 | β |
| fill_holes | BOOLEAN | false | β |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | β |