PyMatting: A Python Library for Alpha Matting
We introduce the PyMatting package for Python which implements various methods to solve the alpha matting problem.
- Website and Documentation: https://pymatting.github.io/
- Benchmarks: https://pymatting.github.io/benchmark.html
Given an input image and a hand-drawn trimap (top row), alpha matting estimates the alpha channel of a foreground object which can then be composed onto a different background (bottom row).
PyMatting provides:
- Alpha matting implementations for:
- Foreground estimation implementations for:
- Closed Form Foreground Estimation [1]
- Multilevel Foreground Estimation (CPU, CUDA and OpenCL)
- Fast multithreaded KNN search
- Preconditioners to accelerate the convergence rate of conjugate gradient descent:
- The incomplete thresholded Cholesky decomposition (Incomplete is part of the name. The implementation is quite complete.)
- The V-Cycle Geometric Multigrid preconditioner
- Readable code leveraging NumPy, SciPy and Numba
Getting Started
Requirements
Minimal requiremens
- numpy>=1.16.0
- pillow>=5.2.0
- numba>=0.47.0
- scipy>=1.1.0
Additional requirements for GPU support
- cupy-cuda90>=6.5.0 or similar
- pyopencl>=2019.1.2
Requirements to run the tests
- pytest>=5.3.4
Installation with PyPI
pip3 install pymatting
Installation from Source
git clone https://github.com/pymatting/pymatting
cd pymatting
pip3 install .
Example
from pymatting import cutout
cutout(
# input image path
"data/lemur.png",
# input trimap path
"data/lemur_trimap.png",
# output cutout path
"lemur_cutout.png")
Testing
Run the tests from the main directory:
python3 tests/download_images.py
pip3 install -r requirements_tests.txt
pytest
Currently 89% of the code is covered by tests.
Authors
- Thomas Germer
- Tobias Uelwer
- Stefan Conrad
- Stefan Harmeling
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE.md file for details
References
[1] Anat Levin, Dani Lischinski, and Yair Weiss. A closed-form solution to natural image matting. IEEE transactions on pattern analysis and machine intelligence, 30(2):228–242, 2007.
[2] Kaiming He, Jian Sun, and Xiaoou Tang. Fast matting using large kernel matting laplacian matrices. In 2010 IEEE Computer Society Conference on Computer Vision and Pattern Recognition, 2165–2172. IEEE, 2010.
[3] Qifeng Chen, Dingzeyu Li, and Chi-Keung Tang. Knn matting. IEEE transactions on pattern analysis and machine intelligence, 35(9):2175–2188, 2013.
[4] Yuanjie Zheng and Chandra Kambhamettu. Learning based digital matting. In 2009 IEEE 12th international conference on computer vision, 889–896. IEEE, 2009.
[5] Leo Grady, Thomas Schiwietz, Shmuel Aharon, and Rüdiger Westermann. Random walks for interactive alpha-matting. In Proceedings of VIIP, volume 2005, 423–429. 2005.
Metadata
Release files for PyMatting 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| PyMatting-1.0.1.tar.gz | 25.1 kB | Without provenance | Details for PyMatting-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| PyMatting-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for PyMatting-1.0.1-py3-none-any.whl |
Total release size: 64.6 kB
Release files / PyMatting-1.0.1.tar.gz
| Download URL | PyMatting-1.0.1.tar.gz |
|---|---|
| Size | 25.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a7f800146a519818b9c7a86990c5516bb05cadde83cb76bbc7b7470c5c01808f
|
|
BLAKE2b-256 checksum How to use checksums |
9ec3ad0ed3064ca5b10ad54c99118f801555c651844c998dd24690a932980b21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.27.0 CPython/3.6.9
|
Release files / PyMatting-1.0.1-py3-none-any.whl
| Download URL | PyMatting-1.0.1-py3-none-any.whl |
|---|---|
| Size | 39.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e80aff9ef4e39791a2c6351e269f4993c59e51b25ca50270c038c15cd6678b31
|
|
BLAKE2b-256 checksum How to use checksums |
9c4dec6187fb5bba130602fdda5ea16f9e206c2719a47e6cff6cc3426d3de0e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.27.0 CPython/3.6.9
|
Security for PyMatting 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.