skillfed

PyMatting

Python package for alpha matting.

pymatting v1.1.15 3.2M downloads/30d#2,702 on PyPI1,914
Permissive license MIT Active released

What it is and what it does

PyMatting is a Python library implementing six different alpha matting algorithms to estimate the alpha channel (transparency) of foreground objects in images. Given an input image and a trimap (a rough manual segmentation into foreground, background, and unknown regions), it computes pixel-level alpha values that allow clean foreground extraction and compositing onto new backgrounds. The library also provides foreground estimation with optional GPU acceleration via CuPy or PyOpenCL.

The package is built on numpy, scipy, and numba for numerical computation and includes specialized tools like fast multithreaded KNN search and preconditioners (incomplete Cholesky decomposition, V-Cycle multigrid) to accelerate convergence. It is designed for readable, maintainable code and includes test coverage of 89%. GPU support is optional and requires separate driver setup.

Use it for:

  • Removing or replacing image backgrounds in photo editing workflows by extracting precise alpha channels
  • Preparing foreground objects for compositing onto different backgrounds in graphics or video production
  • Batch processing images to generate clean cutouts for e-commerce or product photography
  • Integrating alpha matting into image segmentation pipelines alongside other computer vision tasks
  • Accelerating foreground estimation on GPU-equipped systems for high-throughput applications

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

PyMatting solves the alpha matting problem—extracting foreground objects from images given a hand-drawn trimap—using multiple algorithmic approaches and provides foreground estimation with optional GPU acceleration.

Yes. PyMatting is actively maintained, has no known vulnerabilities, installs with low friction, and is licensed permissively. Install it if you need to solve alpha matting problems or extract foreground objects from images with trimap guidance. Skip it if you require deep learning–based matting or have no use for trimap-driven segmentation.

Install

pymatting on PyPI

pip

pip install pymatting

uv

uv add pymatting

poetry

poetry add pymatting

Installing PyMatting

Before you install

Low friction: pure Python wheel with four well-established numeric dependencies (numpy, pillow, numba, scipy). Repository is active with recent commits and 1914 stars. Last release was 200 days ago.

License in practice

MIT license is permissive; you can use, modify, and distribute PyMatting with minimal restrictions, provided you include the license notice.

Quickstart

pip install pymatting

from pymatting import cutout

cutout(
    "input_image.png",
    "input_trimap.png",
    "output_cutout.png"
)

First import takes a minute due to compilation. GPU support requires separate driver installation and optional dependencies.

Verify before relying

  • Performance characteristics and typical runtime for different image sizes and matting methods
  • Memory requirements for large-scale batch processing
  • Accuracy comparison with other alpha matting approaches

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3)
Install friction low — pure-Python wheel
Runtime dependencies 4 — numpy, pillow, numba, scipy
Maintenance actively maintained — 200 days since the last release
Last repo commit
First released
Downloads 3,205,995/month — #2,702 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pymatting-1.1.15-py3-none-any.whl

Keywords: alpha, matting

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3

Tags

alpha matting image segmentationforeground extraction from imagestrimap-based image compositingalpha channel estimationimage matting algorithmsbackground removal mattingforeground estimation GPU
image-processingcomputer-visiongpu-optional

More Scientific/Engineering packages