Giter Club home page Giter Club logo

closed-form-matting's Introduction

Closed-Form Matting

Python implementation of image matting method proposed in A. Levin D. Lischinski and Y. Weiss. A Closed Form Solution to Natural Image Matting. IEEE Conf. on Computer Vision and Pattern Recognition (CVPR), June 2006, New York

The repository also contains implementation of background/foreground reconstruction method proposed in Levin, Anat, Dani Lischinski, and Yair Weiss. "A closed-form solution to natural image matting." IEEE Transactions on Pattern Analysis and Machine Intelligence 30.2 (2008): 228-242.

Requirements

  • python 3.5+ (Though it should run on 2.7)
  • scipy
  • numpy
  • matplotlib
  • sklearn
  • opencv-python (for CLI of solve_foregound_background.py)

Usage

Closed-Form matting

  • mylambda (λ) is a constant controlling the users confidence in the constraints.
  • eps (ε) is a constant controlling the smoothness of alpha.

Running the demo:

python closed_form_matting.py

Python interface:

from closed_form_matting import closed_form_matte
...
alpha = closed_form_matte(image, scribbled_img)

Foreground and Background Reconstruction

CLI interface (requires opencv-python):

./solve_foregound_background.py image.png alpha.png foreground.png background.png

Python interface:

from solve_foregound_background import solve_foregound_background
...
foreground, background = solve_foregound_background(image, alpha)

Results

Original image Scribbled image Result

More Information

This version of matting laplacian does not support computation over only unknown regions. The computation is generally faster than the matlab version regardless thanks to more vectorisation. Note. The computed laplacian is slightly different due to array ordering in numpy being different than in matlab. To get same laplacian as in matlab change,

indsM = np.arange(h*w).reshape((h, w)) ravelImg = img.reshape(h*w, d) to indsM = np.arange(h*w).reshape((h, w), order='F') ravelImg = img.reshape(h*w, d, , order='F'). Again note that this will result in incorrect alpha if the D_s, b_s orderings are not also changed to order='F'F.

For more information see the orginal paper http://www.wisdom.weizmann.ac.il/~levina/papers/Matting-Levin-Lischinski-Weiss-CVPR06.pdf The original matlab code is here http://www.wisdom.weizmann.ac.il/~levina/matting.tar.gz

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.

closed-form-matting's People

Contributors

marcoforte avatar merofeev avatar

Watchers

 avatar  avatar

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.