Mask Segmentation🐰
Split one messy mask into per-region pieces
- image
- mask
- segmented_images
- segmented_masks
Say you've painted one mask that covers three separate objects in a photo - three faces, three logos, three products on a shelf - and you want to run different processing on each one instead of treating them as a single blob. That's the exact problem Mask Segmentation solves. It's the entry door into ComfyUI-Loop-image's batch pipeline: feed it an image and a mask, and it hands you back a list of images and a list of masks, one pair per disconnected region.
How it actually splits things
Under the hood this is connected-component analysis - the same idea as "flood fill and count the islands." Any pixels in your mask that touch each other (directly or diagonally) count as one region; anything separated by unmasked space becomes its own region. Holes inside a region are preserved rather than filled in, so a donut-shaped mask stays a donut, not a solid disc.
The order those regions come out in isn't random: they're sorted left-to-right first, then top-to-bottom, based on each region's leftmost and topmost pixel. Three blobs in a mask become iteration 0 (leftmost), iteration 1 (middle), iteration 2 (rightmost) - and that ordering is what determines which region gets processed on which pass once you feed the output into CyberEve_BatchImageLoopOpen. If your mask's regions overlap or touch, they'll merge into one segment rather than splitting - segmentation only cares about connectivity, not about what you meant to separate.
Inputs and outputs
image(required, IMAGE) - the full source image.mask(required, MASK) - your multi-region mask, drawn however you like (manually, from a detector, whatever produces a mask covering more than one area).
Outputs:
segmented_images- the image cropped/grouped per region, one entry per detected blob.segmented_masks- the matching mask for each region.
Both outputs are lists, and they're built specifically to feed straight into CyberEve_BatchImageLoopOpen's segmented_images / segmented_masks inputs - that's the only place they're meant to go. This node doesn't do anything with the regions itself; it just cuts the problem into pieces for the loop to chew through one at a time.
Installing it
It ships as part of the ComfyUI-Loop-image pack, so you install the whole pack once and get all seven of its nodes, this one included. Easiest path: open ComfyUI Manager, search for "ComfyUI-Loop-image", install, restart. Manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/WainWong/ComfyUI-Loop-image
Restart ComfyUI afterward. There's nothing to download here beyond the code - no checkpoint, no external model, no GPU work. This node runs as plain CPU image logic during the graph pass, so there's no cold-start or VRAM cost to worry about specific to it. Once installed, look for it under the CyberEveLoop🐰 category (right-click → Add Node), alongside the rest of the pack.
Where this trips people up
The most common surprise is a mask that "should" split into three regions but comes out as one. Nine times out of ten it's because the regions actually touch somewhere - a single stray brush stroke connecting two areas, or two shapes that share an edge pixel, is enough to merge them into one component. Zoom in on your mask edges if the region count doesn't match what you expected.
The other one: if you only need a single region processed, you don't need this node at all - it exists specifically for the "split into many, process each differently, recombine" workflow. For a single masked area, skip straight to whatever processing node you'd use normally; there's no loop to build. And since this pack hasn't shipped an update since January 2025, don't expect anything fancier than basic connected-component segmentation - it's not object-aware, so it won't tell "person A" from "person B" if their masks are drawn as one continuous blob, only "connected" from "disconnected."
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| segmented_images | IMAGE | — |
| segmented_masks | MASK | — |