Mask Fill Holes
Patch the gaps inside a mask — Mask Fill Holes
- 遮罩
- 遮罩
Masks from real models have holes. A background remover leaves a speck of background in the middle of the subject. A segmentation mask has a gap where a hand crossed an arm. A detection mask has a hole where a highlight blew out. If you feed that into an inpaint pass, the holes become regions the model treats as "don't touch" - and you get a strange patchwork of edits. wcx_MaskFillHoles closes exactly those interior gaps: any region entirely surrounded by masked pixels gets filled in.
Mechanically it uses binary_fill_holes from scipy, which does precisely what the name says: it finds enclosed background areas inside a foreground region and turns them into foreground. It works per-mask, handles single masks and whole batches (a batch in, a batch out), and the key detail is that it only fills holes inside the masked region - it won't expand the mask outward or bridge across open space. The shape stays exactly as bounded as it was; it just gets solid.
Input is a single mask socket (labeled 遮罩 in the UI - this pack uses Chinese port labels on a few nodes, harmless once you know), output is mask with the holes patched.
Where it shines:
- After background removal or segmentation. Those masks are exactly where interior holes come from - and per the KB's masking doc, this is part of cleaning up a mask before it feeds a detailing loop, so a single inconsistent gap doesn't produce a visible artifact in the final composite.
- Before batch work. If you're joining masks or running them through a batch pass (this pack's
MaskBatch), patching holes first means every frame carries a solid region instead of a quirky one.
Gotchas:
- It fills, it doesn't grow. A mask that's too small for the actual subject still won't cover it - the node only closes enclosed holes, not under-coverage. Pair it with
Mask Growwhen you need both. - It relies on scipy. ComfyUI ships scipy as part of its core requirements, so this should just work - but if you've got a stripped-down custom Python environment and the node errors on import,
binary_fill_holesis the dependency it's complaining about. - It can mask details you wanted. If a "hole" was actually a separate region you intended to leave unmasked - a distinct object fully surrounded by the selection - it gets absorbed. When in doubt, look at the mask before and after.
Standard light install:
# ComfyUI Manager: search "ComfyUI-Practical-Tools" → Install → restart
# or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/wenchengxiang/ComfyUI-Practical-Tools
# restart ComfyUI
It's a surgical little cleanup node, and in a pipeline that produces masks automatically it's the difference between masks you can trust and masks you have to babysit.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| 遮罩 | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| 遮罩 | MASK | — |