Nodes/ComfyUI-Apt_Preset/Mask_split_mulMask
ComfyUI Node

Mask_split_mulMask

Break one multi-blob mask into up to 4 separate masks

By cardenluo·Created 2 years ago·Updated 21 days ago· 309
Mask_split_mulMask
  • mask
  • mask1
  • mask2
  • mask3
  • mask4
  • rest_mask
ignore_threshold0

You ran a segmentation or detection pass and got back one mask with several disconnected blobs in it - say, three faces in a group photo, or four separate objects a detector found. Problem is, most detail-refinement or per-region workflows want to treat each blob independently, and a single combined mask doesn't let you do that. Mask_split_mulMask takes that one lumpy mask and hands you back the individual pieces as separate masks.

It's a small, single-purpose node from ComfyUI-Apt_Preset, the same big preset/utility pack that ships Mask_splitMask_by_color and Mask_transform_sum. All three live in the pack's mask toolbox and none of them need models or extra downloads.

How it works

The node finds connected regions of white (unmasked-out) pixels in your input mask - standard connected-component analysis - and assigns each region to its own output slot. It only exposes four numbered slots, so if your mask has more than four separate blobs, the first four (by whatever internal ordering it uses, likely size or position) each get their own output, and everything left over gets bundled together into rest_mask rather than dropped. That's a sane default: you don't lose data, you just lose per-blob separation for anything past the fourth.

ignore_threshold is the one knob that changes what counts as a "real" blob in the first place - set it above zero and any connected region smaller than that pixel count gets filtered out before the split happens, instead of eating up one of your four precious slots. That matters more than it sounds like: a segmentation mask with a few stray one-pixel artifacts will otherwise burn a slot on noise instead of your actual fourth object.

Inputs and outputs

  • mask - the multi-blob mask you're splitting apart. Comes from wherever you generated it: a detector, a manual paint, another mask node in the chain.
  • ignore_threshold - minimum blob size in pixels to keep, 0 to 2048, default 0 (keep everything). Raise it to drop tiny noise blobs before they take a slot.

You get five MASK outputs: mask1 through mask4 for the individual regions, and rest_mask for anything beyond the first four (or an empty mask if there were four or fewer to begin with). Wire each one into whatever per-region step you're running - a detail pass, a separate ControlNet region, a different prompt per subject - and use rest_mask as either a catch-all pass or just ignore it if you know you never have more than four regions.

Installing it

Through ComfyUI Manager: search "ComfyUI-Apt_Preset", install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git

Restart ComfyUI afterward. Windows users get an install.bat in the repo for dependencies; on Linux or Mac, install from the requirements file inside your ComfyUI venv the normal way. Nothing about this specific node needs a model download - it's geometry, not inference.

This is a fairly obscure pack outside its own user base - a single-author project with an active commit history but not much presence in general ComfyUI discussion - so lean on the GitHub issues page over forum searches if you hit something odd.

Common issues

Fewer masks than blobs you expected. Check ignore_threshold first - if it's set above zero, small regions are being filtered out before the split, which is by design but easy to forget you set. Drop it back to 0 to confirm.

A region you care about landed in rest_mask instead of getting its own slot. You've got more than four connected regions in the source mask, and the fifth-plus all fall into the catch-all. There's no way around this with this node alone short of pre-splitting your source mask into fewer pieces (e.g. mask off unrelated regions before this node sees them) - it only exposes four individual slots by design.

Two objects that should be separate came out as one blob. That means they were touching or overlapping in the source mask, so connected-component analysis sees them as a single region. Fix it upstream, in whatever produced the mask - a small erosion/gap between the two shapes before this node runs will usually separate them.

CategoryApt_Preset/mask

Inputs (2)

NameTypeDefaultDescription
maskMASK
ignore_thresholdINT00–2048

Outputs (5)

NameTypeDescription
mask1MASK
mask2MASK
mask3MASK
mask4MASK
rest_maskMASK