https://github.com/louisfb01/iterative-grabcut
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. Then, it removes the background and makes it transparent.
https://github.com/louisfb01/iterative-grabcut
background background-image background-subtraction grabcut grabcut-segmentation iterative-methods notebook notebook-jupyter notebooks opencv opencv-python opencv2 python python3
Last synced: 3 months ago
JSON representation
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. Then, it removes the background and makes it transparent.
- Host: GitHub
- URL: https://github.com/louisfb01/iterative-grabcut
- Owner: louisfb01
- License: mit
- Created: 2021-04-16T16:14:49.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-12T15:58:19.000Z (over 3 years ago)
- Last Synced: 2025-04-05T09:11:13.907Z (6 months ago)
- Topics: background, background-image, background-subtraction, grabcut, grabcut-segmentation, iterative-methods, notebook, notebook-jupyter, notebooks, opencv, opencv-python, opencv2, python, python3
- Language: Jupyter Notebook
- Homepage: https://www.louisbouchard.ai/grabcut-notebook-implementation/
- Size: 2.62 MB
- Stars: 45
- Watchers: 4
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# iterative-grabcut: Using simple rectangle for identifying foreground items
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](https://opencv24-python-tutorials.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_grabcut/py_grabcut.html) shown in the [High-Quality Background Removal Without Green Screens | State of the Art Approach Explained](https://youtu.be/rUo0wuVyefU) video on What's AI's channel.
## How does it work? With example
0. Clone the repo and install the requirements in your environment using pip install -r requirements.txt
1. Upload your image.
2. Create a rectangle over your image including all your foreground objects.
3. Remove the background using GrabCut algorithm.
4. If improvement is needed, draw on the image, left click (white) = foreground and right click(black) = background.
5. Remove the background using GrabCut algorithm.
6. Return to step 4 or end.## Video demos
### Example with one iteration to correct the first pass of the algorithm:
https://user-images.githubusercontent.com/70274208/115054227-00367880-9eae-11eb-8281-320c5fa658f1.mp4
### Example with harder picture and multiple iterations:
https://user-images.githubusercontent.com/70274208/115054217-fca2f180-9ead-11eb-8777-373596f75165.mp4
## Results:
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
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