遮罩拆分丨组件
One mask, five objects — split it into a mask per component
- mask
- reference_image
- mask_list
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 bysmall_region_handling:merge(default) glues it to the nearest big component withinmerge_distance_ratio(float, default 2.0, scaled against 5% of image height),removedeletes it,keepleaves it alone. - Text preservation -
text_preservationdefaults tochinese_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, orchinese_optimizedrun morphological preprocessing and re-merge likely-text components;disabledturns 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.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| min_component_size | INT | 1001–10000 | — |
| small_region_handling | COMBO | merge | 3 options: merge, remove, keep |
| merge_distance_ratio | FLOAT | 2.00.1–10 | — |
| text_preservation | COMBO | chinese_optimized | 4 options: auto, aggressive, chinese_optimized, disabled |
| structure_preservation | COMBO | auto | 3 options: disabled, auto, enhanced |
| output_all_components | BOOLEAN | true | — |
| preserve_original_values | BOOLEAN | true | — |
| reference_imageopt | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask_list | MASK | — |