Iterative Grabcut Save

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.

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 shown in the High-Quality Background Removal Without Green Screens | State of the Art Approach Explained video on What's AI's channel.

How does it work? With example

  1. Clone the repo and install the requirements in your environment using pip install -r requirements.txt
  2. Upload your image.
  3. Create a rectangle over your image including all your foreground objects.
  4. Remove the background using GrabCut algorithm.
  5. If improvement is needed, draw on the image, left click (white) = foreground and right click(black) = background.
  6. Remove the background using GrabCut algorithm.
  7. 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

Open Source Agenda is not affiliated with "Iterative Grabcut" Project. README Source: louisfb01/iterative-grabcut

Open Source Agenda Badge

Open Source Agenda Rating