Separate Mask Components
Split one messy mask into individual blobs
- mask
- mask
- mask_mappings
Say you've got a mask covering three faces in a group photo - one mask, three disconnected white blobs. Most of the pack's nodes treat a mask as one thing, which means if you cut it out with Cut By Mask you'd get one crop containing all three faces jammed together, not three separate crops you can process individually. Separate Mask Components is the fix: it finds every disconnected white region in a mask and splits them into a batch of individual masks, one blob per mask.
"Disconnected" is doing real work in that description - any pixel value above 0 counts as part of a region, and regions are grouped by contiguity (connected components, in image-processing terms). Three faces that don't touch become three separate masks in the output batch. If two blobs happen to touch or overlap even slightly, they get treated as one connected region, not two - worth knowing if your source mask is a little noisy, since a stray connecting pixel between two things you wanted split can quietly merge them into one component. Mask Morphology's open operation, run first, cleans that up.
The inputs that matter
- mask - the mask to separate.
Two outputs, and both matter: mask is the batch of individual per-blob masks. mask_mappings is a MASK_MAPPING - not something you look at directly, but a piece of bookkeeping that records which mask in the batch belongs to which position, so downstream nodes can put things back together correctly.
That second output is the one people miss and then get confused later. If you take this batch of separated masks into Cut By Mask or Paste By Mask, wire mask_mappings into their optional mask_mapping_optional input. Without it, those nodes have no way to know that mask #2 in the batch corresponds to the second blob from the original image rather than some other image entirely - and if you're only ever working with a single source image and a single mask, you'll likely be fine either way, but the moment you're batching multiple images through this pipeline, skipping the mapping is exactly how a paste ends up on the wrong face.
Installing it
Separate Mask Components is part of Masquerade Nodes. Install through ComfyUI Manager (search "Masquerade Nodes") or manually: cd ComfyUI/custom_nodes && git clone https://github.com/BadCafeCode/masquerade-nodes-comfyui, then restart ComfyUI. No models, no extra dependencies - connected-component analysis is standard array math, nothing to download.
Common issues
The two things that actually bite people: forgetting to wire mask_mappings downstream (symptom: cuts and pastes land on the wrong region once you're working with more than one source image), and feeding in a noisy mask where blobs you wanted separated are actually touching by a pixel or two (symptom: you expected three masks out and got two, because two blobs merged into one connected region). For the second one, run the source mask through Mask Morphology with open at a small distance before this node - that trims the thin connecting bridges that cause false merges without meaningfully shrinking the real blobs.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | IMAGE | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| mask | IMAGE | — |
| mask_mappings | MASK_MAPPING | — |