Nodes/SDVN_Comfy_node/🧩 Mask Regions
ComfyUI Node

🧩 Mask Regions

Split one mask into separate per-area masks

By StableDiffusionVN·Created 2 years ago·Updated about a month ago· 118
🧩 Mask Regions
  • mask
  • layer_mask

One mask with three separate blobs in it goes in; three separate masks come out. That's the job. When you've got a mask covering several disconnected areas - two faces in a group shot, a handful of objects to remove, three spots to retouch - this node breaks it apart into an individual mask per area, handed downstream as a list. It's the setup step for treating each region on its own instead of blasting them all with the same generation.

This is where it earns its keep: paired with SDVN's crop-and-stitch, it lets you inpaint every region separately and at full resolution, then reassemble. The README says it outright - it works exceptionally well with the inpaint crop node set. That combination is the pack's answer to "fix five things in one image without them fighting each other."

How it works

It runs connected-component detection on the mask: it finds each contiguous blob of masked pixels and emits it as its own mask. Areas that touch get grouped into one region; areas separated by a gap of unmasked pixels become distinct masks. The output is a list of masks, so the count varies with your input - three separate blobs give three masks, and whatever consumes the list iterates over each one.

The natural pipeline is: Mask Regions splits the mask → feed each region to Inpaint Crop → generate each crop → Loop Inpaint Stitch reassembles them all into one image. Because ComfyUI iterates lists automatically, you build that once and it processes every region.

The inputs and outputs

There's a single input - mask - the combined mask you want split.

The single output is layer_mask (a MASK list) - one mask per detected region. Wire it into your per-region processing; downstream nodes run once per mask in the list.

That's the entire node. No knobs, which is either refreshingly simple or slightly limiting depending on your taste - there's no threshold or minimum-size control, so it splits on whatever's contiguous.

Common issues

Two areas I wanted separate came out as one mask. They're touching, or nearly. Connected-component splitting groups anything contiguous, so if two blobs share even a thin bridge of masked pixels they count as one region. Clean the gap between them in your masking step, or use a detection node (like the pack's Yolo Seg Mask) that separates by object rather than by connectivity.

Tiny stray masks in the output. Specks of masked pixels - antialiasing fringe, a stray dot - each become their own region, so you can get more masks than you expected. Blur-and-threshold or shrink/grow the mask upstream to clean noise before splitting.

The list count changes between runs. Expected - the number of regions depends on the mask, which depends on whatever generated it (a YOLO detector, a hand paint). If a downstream node needs a fixed count, that's a workflow-design constraint to handle, not a bug here.

Installing SDVN_Comfy_node

ComfyUI Manager: search "SDVN_Comfy_node" → install → restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/StableDiffusionVN/SDVN_Comfy_node

Then pip install -r custom_nodes/SDVN_Comfy_node/requirements.txt from the ComfyUI root and restart. It's designed to work with the pack's own crop/stitch nodes, so you don't need any external inpaint pack. Find it under 📂 SDVN / 🎭 Mask.

Category📂 SDVN/🎭 Mask

Inputs (1)

NameTypeDefaultDescription
maskMASKMask cần tách

Outputs (1)

NameTypeDescription
layer_maskMASKDanh sách mask vùng.