This algorithm uses a rectangle made by the user to identify the foreground item. Then, the user can edit to add or remove objects to the foreground. Once done, it removes the background and makes it transparent (adds alpha channel) and saves it.
This is a simple notebook implementing the GrabCut algorithm shown in the High-Quality Background Removal Without Green Screens | State of the Art Approach Explained video on What's AI's channel.
- Clone the repo and install the requirements in your environment using pip install -r requirements.txt
- Upload your image.
- Create a rectangle over your image including all your foreground objects.
- Remove the background using GrabCut algorithm.
- If improvement is needed, draw on the image, left click (white) = foreground and right click(black) = background.
- Remove the background using GrabCut algorithm.
- Return to step 4 or end.
2020-08-22_18-02-12_1.mp4
2020-08-22_18-02-12.mp4
References:
Interactive Foreground Extraction using GrabCut Algorithm, OpenCV, (2013), https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_grabcut/py_grabcut.html