Alpha Matte (DEPRECATED, use ImageMatting)
Deprecated, use Image Matting instead
- images
- alpha_trimap
- alpha
- fg
- bg
Another one that's been superseded: the display name reads "Alpha Matte (DEPRECATED, use ImageMatting)", and the current README no longer lists it - Image Matting has taken its place, described as taking "an image and trimap/mask, and refines the matte edges with closed-form matting... good for cleaning up SAM segments or hand drawn masks." Same underlying algorithm, current name. If you're building something new, go straight to Image Matting.
What it did, and why it still matters conceptually
This is trimap-based alpha matting - genuinely one of the two real approaches to extracting a clean alpha channel, and worth understanding even now that trimap-free models exist. A trimap is a rough three-value map: definitely foreground, definitely background, and "unknown" - usually a hand-drawn or SAM-generated rough selection, thickened along the edges. Closed-form matting then solves for the actual fractional alpha value in that unknown band, using local color statistics to figure out how much of each pixel is foreground versus background. This matters specifically for fine, semi-transparent edges - hair, fur, motion blur - where a hard yes/no mask is structurally wrong; the real answer at a hair-edge pixel might be "60% foreground."
That's a genuinely different approach from the newer trimap-free matting networks (BiRefNet's matting weights, for instance), which predict fractional alpha directly from the image with no separate trimap step. If you already have a rough mask that just needs its edges refined - a SAM output, something you drew by hand - trimap-based matting is still exactly the right tool, and it's cheap: no neural network inference beyond your existing mask.
Inputs and outputs that matter
images- your source image.alpha_trimap- the rough trimap (foreground/background/unknown), as an image.preblur(0-256, default 8) - smooths the trimap before solving, which helps the optimization behave.blackpoint(0-0.99, default 0.01) /whitepoint(0.01-1, default 0.99) - trims the extreme ends of the solved alpha range.max_iterations(100-10000, default 1000) - the optimization's iteration cap. Higher can improve convergence on tricky images at the cost of time.estimate_fg-trueorfalse. When true, also solves for what the foreground colors would be underneath the semi-transparent edge pixels, useful when compositing onto a new background and you don't want the old background's color bleeding through.
Outputs: alpha, fg, and bg - the solved alpha matte plus, when estimate_fg is on, the estimated foreground and background color layers.
Installing it
ComfyUI Manager: search ComfyUI Image Filters, or:
cd ComfyUI/custom_nodes
git clone https://github.com/spacepxl/ComfyUI-Image-Filters
Restart. No model weights - closed-form matting is a classical optimization, not a neural model. The recurring dependency issue for this whole pack is opencv version conflicts with other installed node packs; run import_error_install.bat from the repo, or manually reinstall just opencv-contrib-python after removing other opencv variants.
Where people get burned
A bad trimap produces a bad matte, full stop - if your "unknown" band is too thin, the solver doesn't have enough context to work with; too thick, and it's slow and can produce mushy results. preblur helps smooth over a rough trimap but can't fix one that's fundamentally too tight. And since this is deprecated, treat any new work as belonging in Image Matting instead - same mechanism, current node.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| alpha_trimap | IMAGE | — | |
| preblur | INT | 80–256 | — |
| blackpoint | FLOAT | 0.010–0.99 | — |
| whitepoint | FLOAT | 0.990.01–1 | — |
| max_iterations | INT | 1000100–10000 | — |
| estimate_fg | COMBO | 2 options: true, false |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| alpha | IMAGE | — |
| fg | IMAGE | — |
| bg | IMAGE | — |