pymatting

pymatting: Estimate Foreground Transparency in Images

PyMatting is a Python library for estimating an image’s foreground transparency from a trimap, with several established matting algorithms and foreground estimation methods. It suits image-processing workflows that need controllable, trimap-based cutouts rather than a turnkey deep-learning segmentation model.

Stars
1.9k
Forks
227
Stars, last 10 days
+1
Last commit
1 month ago
Contributors
13

Our take

Activerecent releases

Health score

41/100

How it is scored
Activity
45
Community
55
Issues
21
Pull requests
44

+1 stars in the last 10 days

PyMatting is an active, MIT-licensed specialist library with multiple matting methods, but its trimap-driven workflow makes it a focused component rather than a turnkey background-removal system.

Good fit if

  • Your Python image-processing pipeline can supply trimaps and needs alpha matting or foreground estimation.
  • You want several established algorithm implementations in one library, with optional GPU acceleration for foreground estimation.
  • You need an actively maintained project: it has recent commits and releases, contributions from multiple people, and CI and tests.

Look elsewhere if

  • You need automatic foreground selection without a trimap, or a complete segmentation model and user workflow.
  • You require GPU acceleration for alpha estimation, which the project does not provide.
  • Your application is not built around Python or the NumPy/SciPy ecosystem.
All health signals
Last commit2026-09-08 (1 month ago)
Commits, last 90 days2
Releases, last 12 months2 (latest v1.1.16, 2026-09-08)
Contributors13 (top contributor: 48% of commits)
Issues closed, last 90 days0
Pull requests merged, last 90 days1
Project age6 years

Checked on 2026-10-11 with the GitHub API.

Overview

PyMatting estimates the alpha channel of a foreground object from an image and a trimap that marks known foreground, known background, and unknown pixels. The resulting transparency map can be used to composite the subject onto another background.

It is a collection of classical and learning-based matting algorithms for Python, with a command-line cutout workflow as well as library APIs. It is most useful when a workflow can provide a trimap and needs explicit control over matting and foreground estimation.

Key Features

  • Implements closed-form, large-kernel, KNN, learning-based, random-walk, and shared-sampling alpha matting.
  • Provides closed-form and fast multi-level foreground estimation.
  • Includes multithreaded KNN search and preconditioners for conjugate-gradient solvers.
  • Offers optional CuPy and PyOpenCL acceleration for foreground estimation.
  • Supports both Python use and a command-line tool for producing cutouts.
  • Uses NumPy, SciPy, and Numba, with readable implementations intended for scientific Python workflows.

Use Cases

  • A developer building a background-removal pipeline can generate or collect trimaps, then use PyMatting to refine object edges into an alpha channel.
  • A researcher comparing matting approaches can use the included family of classical and learning-based methods in a Python environment.
  • An image-processing application can offer trimap-assisted cutouts when users need more control over foreground and background boundaries than a simple mask provides.
  • A team processing batches of images can call the library or CLI from an existing Python workflow, and optionally use GPU support for foreground estimation where supported.

What you need

Detected in the repository

  • Python >=3 (from pyproject.toml)
  • A test suite and automated checks on GitHub Actions

License in plain words

MITpermissive

  • Commercial use: yes
  • Modify and redistribute: yes
  • You must keep: the copyright and license notice
  • Share your changes: no

A summary, not legal advice: the LICENSE file is what applies.

Getting Started

Install from PyPI:

pip install pymatting

See the README and documentation for trimap formats, examples, and optional GPU setup.

Considerations

The algorithms expect a trimap with known foreground and background regions, so creating suitable trimaps is part of the workflow. GPU support is limited to foreground estimation and requires separately installed CuPy or PyOpenCL dependencies and appropriate drivers. The project is active, with recent releases and contributions from multiple contributors; however, the measured recent window showed no issues closed, so it provides no recent issue-resolution history to assess. The MIT license is permissive and generally allows commercial use, subject to its notice and license terms.

Found this useful?

Share it with someone who would like pymatting.