Smart Fill Transparent Holes
Plug the holes a background removal leaves behind
- target
- source
- image
- filled_mask
Here's a failure mode every background-removal tool shares: you cut the subject out, and the alpha channel is full of little holes inside the subject. A chain link fence, a net, glasses, fingers overlapping - anything where the background shows through in patches ends up as transparent speckles that the cutout tool faithfully preserved. Smart Fill Transparent Holes is the cleanup pass: it finds the transparent regions that don't touch the image edge and refills them from a source image.
How it works
You feed two images: the target (the cutout with holes) and a source (the original, pre-cutout image - the truth of what was under the background). The node thresholds the target's alpha channel, finds connected transparent regions, and classifies them:
- Regions that touch the frame edge are real background - left alone.
- Regions inside the subject, within your size window, get filled from the source.
The clever bit is that it's not AI guessing - it's literally copying back the original pixels from the source image, so the filled areas match the subject's actual texture. With blend on (default), it alpha-blends the source content in, so semi-transparent holes feather naturally instead of hard-snapping. Regions outside min_hole_size–max_hole_size are skipped, which is how you ignore both noise (too small) and legitimate background (too big). There are also ignore_left/ignore_right/ignore_top/ignore_bottom margins to exclude border strips from being considered "holes" at all.
Under the hood it uses scipy's connected-component labeling and processes the batch across threads, so it stays fast even on multi-frame work. It outputs both the repaired image and a filled_mask showing exactly what it changed - so you can verify nothing got wrongly filled.
Inputs and outputs
target- the image with transparent holes (RGBA).source- the image to pull fill content from.min_hole_size/max_hole_size- size window in pixels; defaults 1 and 15.threshold- alpha below this counts as transparent (default 0.9).blend- alpha-blend the fill vs. hard copy.ignore_*- pixel margins to exclude per edge.
Outputs: image (repaired) and filled_mask (what was filled).
Installing it
From the ComfyUI-SmartImageTools pack:
cd ComfyUI/custom_nodes
git clone https://github.com/slvslvslv/ComfyUI-SmartImageTools
pip install -r ComfyUI-SmartImageTools/requirements.txt
Restart ComfyUI (or ComfyUI Manager → "SmartImageTools"). It pulls in scipy through scikit-image, so the pack's install already covers it.
The honest limits
It only fills interior holes - anything connected to the image border is treated as background by design, which is correct for most cutouts but means a hole that touches the edge won't be patched (that's what the ignore margins are for, to stop it misreading intentional edge transparency). And the fill content is whatever the source image has there, so if your source itself is bad (compressed, blurred), the fill is bad too. For the classic "netting and gaps after matting" case, though, this is the fastest fix in the pack - one node, two images in, clean subject out.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| target | IMAGE | — | |
| source | IMAGE | — | |
| min_hole_size | INT | 11–100000 | — |
| max_hole_size | INT | 151–100000 | — |
| threshold | FLOAT | 0.900–1 | — |
| blend | BOOLEAN | true | — |
| ignore_left | INT | 00–8192 | — |
| ignore_right | INT | 00–8192 | — |
| ignore_top | INT | 00–8192 | — |
| ignore_bottom | INT | 00–8192 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| filled_mask | MASK | — |