Problemadvanced
Image matting
Also called alpha matting.
Recover the opacity alpha of the foreground at each pixel, and often its color, from an image that is a blend alpha F + (1 - alpha) B and a trimap or scribbles.
- Time
- O(n^3) worst
- Where
- n = the number of pixels
- Model
- Real RAM
Image matting is the problem of pulling a soft foreground out of an image. Each pixel color is modeled as a blend of a foreground color and a background color , with an opacity . The task is to find , and usually , at each pixel, so that the foreground can be put on a new background with compositing. Unlike a hard mask from interactive segmentation, the matte keeps hair, fur, smoke, motion blur and the mixed pixels on every edge. With 3 equations and 7 unknowns per color pixel, the problem has no unique answer without more input. That input is a known backing color, two shots against two backings, or a trimap or scribbles from a user together with an assumption about the image.
In plain words
When you cut out a person from a photo, the edge is not sharp. A strand of hair covers only part of a pixel, so the pixel color is a mix of the hair and the wall behind it. Matting finds, for each pixel, how much of it belongs to the person, from none to all, and what color the person has there.
One photo alone does not say this, because many mixes give the same color. So you need more help: a known wall color, two photos against two walls, or a rough map from the user that says "surely person", "surely wall" and "not sure".
Definition
The input is an image with pixels and colors in . The model is the compositing equation
for each pixel . Porter and Duff (1984) used the same equation, the over operator, to put a foreground with an alpha channel on a background. Matting runs it the other way. The output is for each pixel, and in many uses also (and ).
At each color pixel there are 3 equations and 7 unknowns (, and ), so the problem must have more input. The common forms are:
- Known backing. is a known constant color, as in blue screen work.
- Two backings. Two images of the same foreground against two known backings and .
- Trimap. The user marks each pixel as sure foreground (), sure background () or unknown. Only the unknown band must be solved.
- Scribbles. A few strokes of sure foreground and background, with all other pixels unknown.
An answer is judged against a ground truth matte, for example by the sum of absolute differences or the mean squared error over the unknown pixels. These scores are benchmark results.
Variants
- Constant-color (blue screen) matting. One known backing . Smith and Blinn (1996) showed that this has no unique solution in general; it becomes solvable only with an extra rule on , such as "the foreground has no blue".
- Triangulation matting. Two shots against two backings. This gives 6 equations for 4 unknowns ( and ), and the solution is unique when the backings differ at the pixel (Smith and Blinn 1996).
- Natural image matting. An arbitrary background, with a trimap or scribbles. This is the usual meaning of "image matting" today.
- Video matting. A matte for each frame that also stays stable in time.
- Environment and shadow matting. Extended models that also capture how the foreground bends or reflects the light from the background, or the shadow that it casts. They do not fit the equation above.
Examples
One backing is not enough. Let the backing be blue, , and the observed pixel . The pair , explains it, since . So do with , and with . Each from to gives a valid with all channels in , so the data cannot pick one.
Two backings fix it. Shoot the same pixel again against green, , and get . Subtracting the two equations removes :
Here and , so and . In general, the least squares answer is . Then , so .
A trimap with a natural background. The closed-form matting page works through a small gray image with scribbles. It assumes that and are nearly constant in each small window, and then is the solution of one sparse linear system.
Known algorithms
| Method | Input | Main assumption | Cost | Kind of result |
|---|---|---|---|---|
| Triangulation (Smith and Blinn 1996) | two backings | the same and in both shots | exact under the model | |
| Blue screen rules (Vlahos and others) | one backing | a rule on the colors of | exact only if the rule holds | |
| Bayesian matting (Chuang and others 2001) | trimap | and near Gaussian color clusters of nearby known pixels | iterative per pixel | local optimum of a posterior |
| Poisson matting (Sun and others 2004) | trimap | the gradient of follows the image gradient | sparse Poisson systems | heuristic |
| Closed-form matting (Levin and others 2006) | scribbles or trimap | and nearly constant in each small window | one sparse linear system | global optimum of its cost |
| Guided filter refinement | rough matte | is locally linear in the image | heuristic | |
| learned matting (2017 on) | trimap, or none | trained on composites | one network pass | learned, no guarantee |
Wang and Cohen (2008) sort the classic methods into methods that sample colors of nearby known pixels, methods that spread with affinities between pixels, and methods that combine both.
| Algorithm | Time | Space | Properties | Code |
|---|---|---|---|---|
| Closed-form matting | O(W^3 H^3) worst · average | O(W^2 H^2) extra | deterministicexactglobal optimuminteractivesoft output | 1 language |
Bounds
All bounds use the real-RAM model with pixels, a fixed window size and a fixed number of neighbors per pixel.
- Without more input there is no unique answer. At each color pixel, 3 equations and 7 unknowns leave a 4-dimensional set of solutions, and with a known backing the set is still not a single point in general (Smith and Blinn 1996, first example above). This is a theorem about the model, not about any algorithm.
- Two backings. If at the pixel, and are unique and cost per pixel, so in total. This is a theorem.
- Closed-form matting. The cost is a quadratic form in with a sparse, positive semidefinite Laplacian, so its minimum under the scribbles is a sparse linear system of size at most . Gaussian elimination on it costs in the worst case, which is the bound in the front matter. With the grid structure, sparse direct solvers and conjugate gradients are much faster in practice; those times are benchmark results.
- Lower bound. Each pixel of the unknown band must be read, so in the worst case. This is a trivial theorem.
Reductions
- From compositing. Matting inverts the over operator of Porter-Duff compositing; a good matte makes image compositing on a new background look right.
- From segmentation. A hard mask from interactive segmentation, such as GrabCut, is eroded and dilated to give a trimap.
- To a quadratic problem. Under the local color line model, and drop out and matting becomes the minimization of under the scribbles; see closed-form matting.
- To harmonic interpolation. With other pixel affinities in place of the matting Laplacian, the same system is a random walker with two labels.
Applications
- Film and television. Blue and green screen keying, and pulling mattes of actors shot on real sets.
- Photo editing. Cutting out people and objects with their hair for a new background, or to blur or adjust only the background.
- Video calls. Replacing or blurring the background of a person in real time.
- Data for learning. Composites of matted foregrounds on many backgrounds give training data for segmentation and matting networks.
References
- Thomas Porter and Tom Duff, Compositing digital images, SIGGRAPH 1984, 253-259, the alpha channel and the over operator
- Alvy Ray Smith and James F. Blinn, Blue screen matting, SIGGRAPH 1996, 259-268, the proof that matting against one known backing color has no unique solution in general, and triangulation with two backings
- Yung-Yu Chuang, Brian Curless, David H. Salesin and Richard Szeliski, A Bayesian approach to digital matting, CVPR 2001, vol. II, 264-271, the trimap, and the maximum a posteriori estimate of F, B and alpha with color clusters
- Anat Levin, Dani Lischinski and Yair Weiss, A closed form solution to natural image matting, CVPR 2006, vol. 1, 61-68, Section 1, the count of 3 equations and 7 unknowns per color pixel
- Jue Wang and Michael F. Cohen, Image and video matting: a survey, Foundations and Trends in Computer Graphics and Vision 3(2), 97-175, 2008, the chapters on color sampling methods and on matting affinities
- Richard Szeliski, Computer Vision: Algorithms and Applications, 1st edition, Springer, 2011, Section 10.4, image matting and compositing
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 23HK0D Edit this page History Report an error Markdown