Skip to main content

Python package for alpha matting.

Project description

PyMatting: A Python Library for Alpha Matting

License: MIT Build Status

We introduce the PyMatting package for Python which implements various methods to solve the alpha matting problem.

Lemur

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:
    • Closed Form Alpha Matting [1]
    • Large Kernel Matting [2]
    • KNN Matting [3]
    • Learning Based Digital Matting [4]
    • Random Walk Matting [5]
  • 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

git clone https://github.com/pymatting/pymatting
cd pymatting
pip3 install .

Very Short 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")

More examples

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyMatting-1.0.0.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PyMatting-1.0.0-py3-none-any.whl (39.4 kB view details)

Uploaded Python 3

File details

Details for the file PyMatting-1.0.0.tar.gz.

File metadata

  • Download URL: PyMatting-1.0.0.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for PyMatting-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7405286bdaf2cde48d035953c03646d736820e1d61df0cde0f53802225db6e13
MD5 14e9af0363bb459f0949b8831b055b1c
BLAKE2b-256 41b718213cb7bb2e30c4f11e5a86f26afc97f00d7fd8a64919ed9ef728fb750d

See more details on using hashes here.

File details

Details for the file PyMatting-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: PyMatting-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 39.4 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for PyMatting-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed678e66d24259e7e72e1145c3a56370cd592aeb8f92bc5dc42cc69364273998
MD5 a386e271f95084103308044b44e10509
BLAKE2b-256 80d2a3d9ee578139c8ab58f21bddc5f661321562d4f38c16d0b594f8015f0966

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page