ComfyUI Node

Split Masks

Break One Mask Into Its Separate Regions

By longgui0318·Created 3 years ago·Updated about a year ago· 8
Split Masks
  • mask
  • masks
ignore_threshold0

Sometimes a single mask isn't really one region, it's several - a segmentation pass that found three separate objects and painted them all white on the same mask, or a hand-drawn mask where you scribbled over two unrelated spots. If you need to treat those regions independently (crop each one separately, apply different strengths, process them one at a time), you first need to pull them apart. That's what Split Masks does: it takes one mask and breaks it into a batch of individual masks, one per disconnected blob.

The inputs are mask, the combined mask you're splitting, and ignore_threshold, an integer (default 0, up to 2048) that filters out regions below a certain size - this is what keeps stray noise pixels or tiny specks from your masking process from coming back as their own "region" cluttering up the batch. Bump it up if your source mask is noisy; leave it at 0 if you trust every blob in there is meaningful. The output is masks, the resulting batch.

The node this pairs with directly, inside the same pack, is Mask Selection Of Masks - split first, then index into the pieces one at a time with that node, which is the standard two-step move whenever you need to go from "one messy mask with multiple things in it" to "process this one specific region." If you're building anything resembling a detect-crop-refine pipeline (the pattern behind Impact Pack's FaceDetailer and friends, just generalized here to whatever mask you hand it), splitting and then selecting is how you get from a single detection pass to per-region processing.

Installing it: comfyui-mask-util is a small utility pack from longgui0318, whose better-known project is comfyui-magic-clothing - a virtual-try-on node wrapper that had a brief burst of Reddit attention in 2024 and has been quiet since. This pack reads like the leftover plumbing from that build: crop math, device/dtype handling, and mask bookkeeping like this node. The GitHub README is just the repo title with no further content, so there's no official usage doc - what's here comes from reading the node's actual inputs and outputs.

Install through ComfyUI Manager (search "comfyui-mask-util") or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/longgui0318/comfyui-mask-util

Restart ComfyUI after. Nothing to download beyond the code itself - connected-component splitting on a mask tensor doesn't need model weights.

Where it bites: the whole node depends on your regions actually being disconnected in the mask - if two objects you want treated separately are touching or overlapping in the source mask, they'll come out as one blob, not two, no matter how you set the threshold. And ignore_threshold is a blunt instrument: set it too low and genuine small regions (a distant face, a small logo) get treated as noise and vanish from the batch; set it too high and you're back to fighting speckle. If your downstream node (like Mask Selection Of Masks) assumes a fixed number or ordering of regions, be aware that both can shift run to run if your source mask isn't perfectly consistent - worth a quick visual check before you wire a fixed index onto the output.

Categorymask

Inputs (2)

NameTypeDefaultDescription
maskMASK
ignore_thresholdINT00–2048

Outputs (1)

NameTypeDescription
masksMASK