FL Separate Mask Components
Split one mask into its separate blobs
- mask
- IMAGE
- MASK_MAPPING
Segmentation hands you one mask. But sometimes that one mask actually contains several separate things - three people in a shot, five scattered objects, a bunch of disconnected regions - all lumped into a single white-on-black image. FL_SeparateMaskComponents takes that combined mask and breaks it into its individual pieces, one mask per connected blob, so you can treat each one on its own. If you've ever wanted to inpaint each object separately, or process regions independently, this is the node that untangles them.
How it works
It runs OpenCV's connected-component labeling on the mask. In plain terms: it finds every isolated island of "white" pixels - regions that touch each other are one component, regions separated by black are different components - and outputs each as its own mask. So a mask with three disconnected blobs becomes a batch of three masks. Alongside that, it emits a MASK_MAPPING that records which output mask came from which source frame, so when you're working across a batch nothing loses track of where it belongs.
This is the enabling step for "do something per-object." Separate the components, loop over them, inpaint or composite each individually, done.
The inputs and outputs
mask- the combined mask to split (passed as an IMAGE here).
Outputs:
IMAGE- the separated masks, one per connected component, as a batch.MASK_MAPPING- the bookkeeping tensor that maps each separated mask back to its source, for correct batch tracking.
Installing it
Comes with the Fill-Nodes pack. ComfyUI Manager: search ComfyUI_Fill-Nodes, install, restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/filliptm/ComfyUI_Fill-Nodes
then restart. It relies on OpenCV (usually already present from other packs) for the component labeling. The "Machine Delusions" banner on startup is just the pack's splash.
Where people get tripped up
- The output count depends on the mask, not on you. You can't set "give me exactly 3." If two objects' masks touch - even by a thread of pixels - they count as one component and come out merged. If a single object's mask has a gap in it, it splits into two. Clean or dilate/erode your mask upstream if the component count is coming out wrong.
- Connected means literally touching. This is topological, not semantic - it doesn't know what an "object" is, only which pixels are joined. Two people standing shoulder to shoulder with overlapping masks are one component to this node.
- Keep the
MASK_MAPPINGwired if you're batching. On a single image you can often ignore it, but across a video or batch it's what stops the separated masks getting scrambled between frames. Feed it wherever the downstream node expects it. - It's the setup, not the payoff. By itself it just gives you masks. The value comes from what you do next - per-component inpainting, per-object compositing - so plan the loop that consumes these before you wire it in.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | IMAGE | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK_MAPPING | MASK_MAPPING | — |