Code Monkey home page Code Monkey logo

bayesian-matting's Introduction

bayesian-matting

Python implementation of Yung-Yu Chuang, Brian Curless, David H. Salesin, and Richard Szeliski. A Bayesian Approach to Digital Matting. In Proceedings of IEEE Computer Vision and Pattern Recognition (CVPR 2001), Vol. II, 264-271, December 2001

Requirements

  • python 3.5+ (Though it should run on 2.7 with some minor tweaks)
  • scipy
  • numpy
  • numba > 0.30.1 (Not neccesary, but does give a 5x speedup)
  • matplotlib
  • opencv
  • sys
  • pathlib
  • argparse

Running the demo

  • 'python bayesian_matting.py gandalf.png gandalfTrimap.png'
  • sigma (ฯƒ) fall off of gaussian weighting to local window
  • N size of window to construct local fg/bg clusters from
  • minN minimum number of known pixels in local window to proceed
  • minN_reduction to reduce N by in event of infinite loop. May reduce accuracy

Results

Original image

Trimap image

Result

More Information

For more information see the orginal project website http://grail.cs.washington.edu/projects/digital-matting/image-matting/ This implementation was mostly adapted from Michael Rubinsteins matlab code here, http://www1.idc.ac.il/toky/CompPhoto-09/Projects/Stud_projects/Miki/index.html http://people.csail.mit.edu/mrub/code/bayesmat.zip

Disclaimer

The code is free for academic/research purpose. Use at your own risk and we are not responsible for any loss resulting from this code. Feel free to submit pull request for bug fixes.

Contact

Marco Forte ([email protected])

Original authors:

Yung-Yu Chuang Brian Curless David Salesin Richard Szeliski

bayesian-matting's People

Contributors

brandon-hastings avatar marcoforte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bayesian-matting's Issues

dead loop in bayesian_matting.py

For some image the code will result in dead loop,cause len(f_weights) < minN or len(b_weights) < minN in code bayesian_matting.py.

numpy.linalg.linalg.LinAlgError: Array must not contain infs or NaNs

I converted the code for python 2.7 by replacing @ with np.matmul and removing nopython=True from the jit decorators. I am getting the following error when I try to run the demo:

bayesian_matting.py:182: RuntimeWarning: invalid value encountered in divide
f, b, alphaT = solve(mu_f, sigma_f, mu_b, sigma_b, p, 0.01, alpha_init, 50, 1e-6)
/mnt/c/Users/Yannis/Desktop/429_project/source/bayesian-matting-master/orchard_bouman_clust.py:18: RuntimeWarning: invalid value encountered in divide
self.mu = np.einsum('ij,i->j', self.X, w)/W
/mnt/c/Users/Yannis/Desktop/429_project/source/bayesian-matting-master/orchard_bouman_clust.py:21: RuntimeWarning: invalid value encountered in divide
self.cov = (np.matmul(t.T,t))/W + 1e-5*np.eye(3)
Traceback (most recent call last):
File "bayesian_matting.py", line 204, in
main()
File "bayesian_matting.py", line 195, in main
alpha = bayesian_matte(img, trimap)
File "bayesian_matting.py", line 177, in bayesian_matte
mu_f, sigma_f = clustFunc(f_pixels, f_weights)
File "/mnt/c/Users/Yannis/Desktop/429_project/source/bayesian-matting-master/orchard_bouman_clust.py", line 36, in clustFunc
nodes = split(nodes)
File "/mnt/c/Users/Yannis/Desktop/429_project/source/bayesian-matting-master/orchard_bouman_clust.py", line 50, in split
C_b = Node(C_i.X[np.logical_not(idx)], C_i.w[np.logical_not(idx)])
File "/mnt/c/Users/Yannis/Desktop/429_project/source/bayesian-matting-master/orchard_bouman_clust.py", line 23, in init
V, D = np.linalg.eig(self.cov)
File "/mnt/c/Users/Yannis/Desktop/429_project/source/venv/local/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 1128, in eig
_assertFinite(a)
File "/mnt/c/Users/Yannis/Desktop/429_project/source/venv/local/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 217, in _assertFinite
raise LinAlgError("Array must not contain infs or NaNs")
numpy.linalg.linalg.LinAlgError: Array must not contain infs or NaNs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.