Nodes/ComfyUI-QING/遮罩拆分丨组件
ComfyUI Node

遮罩拆分丨组件

One mask, five objects — split it into a mask per component

By sheengoa·Created about a year ago·Updated 20 days ago· 16
遮罩拆分丨组件
  • mask
  • reference_image
  • mask_list
min_component_size100
small_region_handlingmerge
merge_distance_ratio2.0
text_preservationchinese_optimized
structure_preservationauto
output_all_componentstrue
preserve_original_valuestrue

A segmentation model gives you one mask per image. But what you wanted was a mask per object - the person, the car, the sign, each separate so you can re-render, upscale, or inpaint them individually. MaskSplitter is the QING pack's answer: it runs connected-component analysis on your mask and hands back a list of masks, one per isolated blob, with enough knobs to keep text and structural pieces from getting chopped into confetti.

How it works

The pipeline is: binarize the mask at 0.5, run OpenCV's connectedComponentsWithStats (8-connectivity), collect every component, then apply three passes of cleanup:

  • Small regions - anything under min_component_size (int, default 100 pixels) is handled by small_region_handling: merge (default) glues it to the nearest big component within merge_distance_ratio (float, default 2.0, scaled against 5% of image height), remove deletes it, keep leaves it alone.
  • Text preservation - text_preservation defaults to chinese_optimized. This is the pack's party trick: letters and characters are often made of several disconnected strokes that would normally split into garbage masks. auto, aggressive, or chinese_optimized run morphological preprocessing and re-merge likely-text components; disabled turns it off.
  • Structure preservation - structure_preservation (disabled / auto / enhanced) tries to merge components that look like parts of one structure.

output_all_components (default true) adds a safety net: if any pixel didn't land in a component, it gets swept into one final mask so nothing silently vanishes. preserve_original_values (default true) keeps the original pixel intensities in each output mask instead of flattening to binary - important if your mask is a soft alpha rather than a hard cut. There's an optional reference_image input, though the core splitting doesn't depend on it.

Output is a single mask_list of type MASK (a list, not a batch) - one mask per component.

Where you'd reach for it

Detailer-style automation lives on this. A single subject-mask from ImageMaskConverter or a segmentation preprocessor becomes N per-object masks, each of which can go to its own sampler pass, its own denoise, its own prompt. That's the loop masking-detection-detailing territory is built on: detect → split → re-render each region → paste back. For masks containing text - signs, logos, subtitles - leave text_preservation on chinese_optimized; it's named that for a reason, and it's the setting you want for CJK text whose strokes barely touch.

Installing it

Comes with ComfyUI-QING:

cd ComfyUI/custom_nodes
git clone https://github.com/GAO-SHIQING/ComfyUI-QING
cd ComfyUI-QING
python install_dependencies.py

Restart after. It needs opencv-python and scikit-image, both in the pack's requirements - the install_dependencies.py script handles them. (The README typo GAOSHI-QING in the clone URL is wrong; use GAO-SHIQING/ComfyUI-QING or let Manager install the pack.)

Things to know

mask_list is a list output, which ComfyUI frontends render as a dynamic number of sockets - nodes that accept MASK lists will take them directly. If min_component_size is set high and small_region_handling is remove, small objects just disappear; that's the feature, but it's also the thing that surprises people the first time. And if you get zero components, the node falls back to returning your original mask - safe, but read the logs if your downstream suddenly has one huge mask.

CategoryQING/遮罩处理

Inputs (9)

NameTypeDefaultDescription
maskMASK
min_component_sizeINT1001–10000
small_region_handlingCOMBOmerge3 options: merge, remove, keep
merge_distance_ratioFLOAT2.00.1–10
text_preservationCOMBOchinese_optimized4 options: auto, aggressive, chinese_optimized, disabled
structure_preservationCOMBOauto3 options: disabled, auto, enhanced
output_all_componentsBOOLEANtrue
preserve_original_valuesBOOLEANtrue
reference_imageoptIMAGE

Outputs (1)

NameTypeDescription
mask_listMASK