Nodes/ComfyUI-SmartImageTools/Smart Fill Transparent Holes
ComfyUI Node

Smart Fill Transparent Holes

Plug the holes a background removal leaves behind

By slvslvslv·Created about a year ago·Updated 25 days ago· 2
Smart Fill Transparent Holes
  • target
  • source
  • image
  • filled_mask
min_hole_size1
max_hole_size15
threshold0.90
blendtrue
ignore_left0
ignore_right0
ignore_top0
ignore_bottom0

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_sizemax_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.

CategorySmartImageTools

Inputs (10)

NameTypeDefaultDescription
targetIMAGE
sourceIMAGE
min_hole_sizeINT11–100000
max_hole_sizeINT151–100000
thresholdFLOAT0.900–1
blendBOOLEANtrue
ignore_leftINT00–8192
ignore_rightINT00–8192
ignore_topINT00–8192
ignore_bottomINT00–8192

Outputs (2)

NameTypeDescription
imageIMAGE
filled_maskMASK