--- id: pymatting version: "1.1.15" license: MIT license_treatment: permissive maintenance: active --- # PyMatting — Python package for alpha matting. License: permissive · Maintenance: active · Downloads: 3.2M/mo ## 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 above — 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 pip install pymatting uv add pymatting 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_current - Install friction: low - Maintenance: active - Downloads: 3.2M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags alpha matting image segmentation, foreground extraction from images, trimap-based image compositing, alpha channel estimation, image matting algorithms, background removal matting, foreground estimation GPU, image-processing, computer-vision, gpu-optional [View on SkillFed](https://skillfed.io/packages/pymatting) · [View on PyPI](https://pypi.org/project/pymatting/)