Implementation of the paper - 'Poisson Matting by Jian Sun, Jiaya Jia, Chi-Keung Tang and Heung-Yeung Shum'
Use the package manager pip to install scipy, pillow, imageio, and cv2.
pip3 install scipy
pip3 install pillow
pip3 install imageio
pip3 install opencv-python
The basic packages of numpy and matplotlib are also required.
pip3 install numpy
pip3 install matplotlib
If imageio/pillow is already installed, make sure to upgrade the version of pillow being used before running the code.
pip3 install --upgrade pillow
Use the commands bash terminal
git clone {url of the page}
or
Click 'Clone or Download' on the top right hand side of the repository.
Go into the directory which holds all the files. Then open the Jupyter Notebook using the command -
jupyter-notebook
The inputs of the code are
- An input image
- Trimap of the input image (of the same size as the input)
- The desired background (of a size bigger than the foreground images)
Running each cell in order would give the desired results - the foreground of input image pasted on a different background.
While doing Local poisson matting, the user needs to manually select the region where the operations need to be performed. Looking at the image after global matting, we can see the range of the x and y coordinates where the pixels need to be altered. Hence this code can be customised depending on the input images and the needs of each user.
The final matte can be further refined by using methods like boosting and highpass filtering. For these two methods, the user must select the regions where the operations are to be done, and set the x and y coordinates in the code accordingly. For this particular image, we are using these two methods. You can also use methods like cloning and channel selection as per your needs.