Skip to content

Alpha matting

Algorithm atlasSegmentation

Estimate fractional foreground coverage using an image and a trimap of known foreground, background and unknown pixels.

Try it on your image ↓

VISUAL WALKTHROUGHSegmentation
REFERENCE INPUTForeground / unknown / background

White is known foreground, black is background, and grey is the unknown band.

RESULTComposite with a new background

Fractional alpha mixes foreground and background instead of producing a hard binary cut.

STEP 03 / 03

Solve for intermediate alpha coverage.

Illustrative example. The stages explain the method; they are not a live OpenCV execution.

Try it on an image

YOUR IMAGE · REAL OPENCV

Experiment at pixel level

Open full lab ↗

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.

Input448 × 320
OutputWaiting for a result

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
Hover to inspect. Click to pin a pixel.
Input
Select a pixel

Output
Select a pixel

Sample models and licenses

When to use it

Recover soft boundaries around hair, motion blur or translucent edges with suitable user or model guidance.

How it works

  1. 01Provide confident foreground and background regions.
  2. 02Propagate colour and affinity information through the unknown region.
  3. 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.