Alpha matting
Estimate fractional foreground coverage using an image and a trimap of known foreground, background and unknown pixels.
White is known foreground, black is background, and grey is the unknown band.
Only the unknown band needs fractional coverage estimates.
This radial example illustrates a soft alpha ramp through the unknown band, not a computed matting solution.
Fractional alpha mixes foreground and background instead of producing a hard binary cut.
Solve for intermediate alpha coverage.
Illustrative example. The stages explain the method; they are not a live OpenCV execution.
Try it on an image
Experiment at pixel level
Build a rectangular trimap: centre is definite foreground, outer frame is definite background, and the band is unknown. The output is an estimated alpha matte, not a semantic object mask.
The engine loads on your first run. Your images stay in this browser.
Scroll over either image to zoom at the pointer. Use the scrollbars to pan both views over the same relative area. Zoom is relative to the input; pixel coordinates belong to each image. Warps can change scene correspondence.
Pixel inspector RGBA · native values · matched scale · 9 × 9 output pixels
Select a pixel
Select a pixel
When to use it
Recover soft boundaries around hair, motion blur or translucent edges with suitable user or model guidance.
How it works
- 01Provide confident foreground and background regions.
- 02Propagate colour and affinity information through the unknown region.
- 03Solve for intermediate alpha coverage.
observed colour = α·foreground + (1−α)·background
What to tune
Prepare the trimap with the exact labels and type the API expects. Keep alpha separate from a binary semantic mask.
Where it breaks down
The trimap is evidence supplied by the application. Similar colours and broad unknown regions can make the matte ambiguous.
TypeScript API
Open an entry for its exact overloads, parameter descriptions, result ownership and pinned upstream source.
All of these calls execute on the CPU. Native objects need explicit disposal. See matrices and ownership and build compatibility.
Related methods
Global thresholding
Divide pixels using one intensity threshold, or choose it automatically with Otsu or the triangle method.
Adaptive thresholding
Compute a different intensity threshold for each local neighbourhood.
Connected components
Give every connected foreground region a distinct integer label.
Contour tracing
Trace the boundary of each binary region as an ordered sequence of points.