Mask Alpha Clean
Scrub the speckles off a matte before it ruins your composite
- mask
- mask
- noise_mask
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 -
strongdoesn't care about thin structures. If your subject has fine strands, start withsoft; only escalate when the noise is actually worse than the edge damage. - Deleting things you meant to keep - run a pass with
detect_only=truefirst and eyeballnoise_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.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| clean_strength | COMBO | balanced | 3 options: soft, balanced, strong |
| detect_only | BOOLEAN | false | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |
| noise_mask | MASK | — |