Nodes/Keep Largest Blob/Keep Largest Blob
ComfyUI Node

Keep Largest Blob

When your background removal leaves confetti, keep the biggest blob

By Lyeeedar·Created 5 months ago·Updated 5 months ago· 0
Keep Largest Blob
  • image
  • image
alpha_threshold10

Every background-removal pipeline - BiRefNet, rembg, SAM cutouts, even LayerDiffusion's native RGBA output - leaves specks. Dust motes, sparkles, a hair detached from the head, a translucent smudge a few pixels wide that the matting model decided was "subject." On a white preview they're barely visible. Composite the cutout onto anything busy and they glow like lint on a black sweater. Keep Largest Blob is a single node that deletes every disconnected alpha island except the biggest one. That's the whole job, and it's a shockingly common gap for such a simple operation.

How it works

The node takes an RGBA image, treats every pixel whose alpha is above a cutoff as "foreground," and runs connected-component labeling over that mask - the same algorithm you met as the "magic wand" in every image editor. It counts the pixels in each contiguous region, keeps the largest, and sets alpha to zero everywhere else. That's it. The implementation is a thin wrapper around scipy.ndimage.label, runs on CPU, and costs effectively nothing in VRAM because it never touches the diffusion pipeline.

One detail in the code is worth knowing because it bites people: only the alpha channel is modified. The RGB values under the removed specks are left intact, and the output is still a 4-channel IMAGE tensor. Feed it to a compositing chain that respects alpha (Save PNG, Composite, alpha-aware layer nodes) and the cutout is clean. Feed it into something that ignores alpha and you'll still see the specks, because the pixels are still there.

The inputs that matter

Two inputs, both required, and honestly you'll touch one of them:

  • image - the RGBA tensor out of your segmentation/background-removal node.
  • alpha_threshold - an int from 1–254, default 10. Any pixel with alpha above this counts as foreground. Leave it at 10 unless your alpha is noisy.

The single output, also called image, is the cleaned RGBA tensor, ready to wire into Save PNG or a composite.

Where it fits

Typical graph: Load Image → BiRefNet/rembg cutout → Keep Largest Blob → Save PNG. It's the cleanup step between "model found the subject" and "I can sell this as a layer." The author's own description targets exactly that: cleaning up background-removed game assets - sprites, icons, product shots where the main subject is one connected thing. It also earns its keep after LayerDiffusion output, which is clean by construction but still throws the odd isolated pixel.

Where it will not help you: any subject that's genuinely two or more disconnected pieces. A character holding a detached prop, a figure whose arm is fully separated from the body - the node keeps one blob and silently deletes the rest. If your subject can split, this isn't the node. And if you raise the threshold to kill haze, you'll also eat soft semi-transparent edges (hair fringes, glass), because those are low-alpha by nature. The default exists for a reason.

Installing it

This pack is tiny - one file, one node, zero models to download. No README, no weights, no GPU-optional side quest. Install via ComfyUI Manager (search "Keep Largest Blob" or the pack title), or:

cd ComfyUI/custom_nodes
git clone https://github.com/Lyeeedar/comfyui-keep-largest-blob

Restart ComfyUI. That's the entire setup.

Gotchas

  • The pack forgets to declare its dependency. pyproject.toml lists no dependencies at all, yet the node imports scipy. It works because ComfyUI core ships scipy anyway - but if your install is stripped down and the node fails to import, this is why.
  • It's unmaintained-ish. One commit, and that commit only fixes the repository URL in the metadata. Nothing has rotted because there's almost nothing to rot, but don't expect fixes.
  • Batches are processed per-frame. In a multi-frame batch, each frame keeps its own largest blob independently - fine for stills, a footgun for animation if the biggest piece changes between frames.

For a 0-impression node nobody talks about, this is quietly one of the most useful little cleanup utilities in the mask toolbox. It does one thing, does it in one click, and it's the difference between a cutout that looks like a cutout and one that looks like a sticker sheet.

Categoryimage/masking

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
alpha_thresholdINT101–254

Outputs (1)

NameTypeDescription
imageIMAGE