PyMatting
Python package for alpha matting.
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 pymattinguv
uv add pymattingpoetry
poetry add pymattingInstalling 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
Tags
More Scientific/Engineering packages
NumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
pandaspandas provides fast, flexible data structures…
permissive · top 100 on PyPI
scipyscipy provides numerical algorithms for…
permissive · top 100 on PyPI
scikit-learnscikit-learn provides a comprehensive Python…
permissive · top 1,000 on PyPI
dilldill extends Python's pickle module to…
permissive · top 1,000 on PyPI
multiprocessMultiprocess is an enhanced fork of Python's…
permissive · top 1,000 on PyPI
transparent-backgroundRemoves backgrounds from images and videos…
permissive · top 15,000 on PyPI
facexlibFacexlib provides a collection of PyTorch-based…
permissive · top 5,000 on PyPI
rembgRemoves image backgrounds using deep learning…
permissive · top 5,000 on PyPI
mmdetMMDetection is an object detection and instance…
permissive · top 15,000 on PyPI
pycudaPyCUDA provides Pythonic bindings to Nvidia's…
permissive · top 15,000 on PyPI
fill-voidsFills interior voids in 2D and 3D binary images…
copyleft · top 15,000 on PyPI
blendmodesApplies a range of blending modes to composite…
permissive · top 15,000 on PyPI
albumentationsAlbumentations applies image transformations to…
permissive · top 5,000 on PyPI
cupy-cuda13xCuPy provides a NumPy and SciPy-compatible…
permissive · top 15,000 on PyPI
blend-modesImplements blend modes (soft light, dodge,…
permissive · top 15,000 on PyPI