Nodes/ComfyUI 1hewNodes/Mask Alpha Clean
ComfyUI Node

Mask Alpha Clean

Scrub the speckles off a matte before it ruins your composite

By 1hew·Created about a year ago·Updated 7 days ago· 33
Mask Alpha Clean
  • mask
  • mask
  • noise_mask
clean_strengthbalanced
detect_onlyfalse

Every background-removal and matting model ships with the same baggage: speckles. A stray dot here, a faint half-transparent fringe there, a tiny disconnected island floating in the background. Feed that raw mask into a composite and the speckles become visible garbage in your output - gray fuzz where the subject ends. Mask Alpha Clean is the quick scrub: it removes weak-alpha noise and tiny disconnected regions from mask batches, with a three-position strength dial and nothing else to fiddle with.

It's the "clean up before you composite" step, and it's one of those nodes you'll stop noticing because it's always just there in front of your crop or blend.

How it works

For each mask frame, the node does two passes. First it thresholds out weak alpha - pixels that are technically non-zero but so faint they're noise (the exact threshold depends on strength). Then it removes small connected components: blobs smaller than a minimum pixel area get deleted. What remains is the clean matte.

The strength preset is the whole control surface:

  • soft - gentle threshold, removes only tiny specks (minimum island ~4px). For delicate structures like hair where you don't want to erode real edges.
  • balanced - the default, a middle ground.
  • strong - aggressive thresholding and island removal (~16px min area). For noisy mattes that need a real scouring.

Outputs are mask (the cleaned result) and noise_mask - a mask where 1 marks the pixels this node decided were noise. And the killer feature is detect_only: flip it on and the node returns your original mask untouched, using noise_mask purely as a detection preview. You get to see exactly what it would delete before you commit to deleting it.

Install

Part of ComfyUI-1hewNodes:

cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes

Restart ComfyUI. No models, no downloads - this is pure numpy connected-component logic.

Where it fits

Right between your matting/background-removal step and any crop, paste, or blend. The pack's own workflow is a natural fit: Detect Remove BG produces the matte, Mask Alpha Clean scrubs it, then Image Mask Blend or Image Crop With BBox Mask uses the clean result. It also cleans up Image Alpha Split-style alpha extractions, which tend to inherit the same speckle problems.

Common issues

  • Hair got nuked - strong doesn't care about thin structures. If your subject has fine strands, start with soft; only escalate when the noise is actually worse than the edge damage.
  • Deleting things you meant to keep - run a pass with detect_only=true first and eyeball noise_mask. It's a free preview; using it costs nothing and prevents "why is my mask missing a chunk?"
  • Batch shapes - 2D masks are expanded to [B,H,W] automatically; input masks with a channel dimension are handled too.

The honest framing: if your mattes are clean, you don't need it. If your mattes come from a real model in the wild, you very likely do - and the detect_only preview makes it safe to use even when you're not sure.

Category1hewNodes/mask

Inputs (3)

NameTypeDefaultDescription
maskMASK
clean_strengthCOMBObalanced3 options: soft, balanced, strong
detect_onlyBOOLEANfalse

Outputs (2)

NameTypeDescription
maskMASK
noise_maskMASK