How does GrabCut Algorithm work for Image Segmentation ?

Region Drawing: In this algorithm, the region is drawn in accordance with the foreground, a rectangle is drawn over it. This is the rectangle that encases our main object. The region coordinates are decided over understanding the foreground mask but imperfect segmentation may occur, marked for manual correction.

Region of Interest (ROI) Selection: The region of interest is decided by the amount of segmentation of foreground and background is to be performed and is chosen by the user. Everything outside the ROI is considered as background and turned black.

Gaussian Mixture Model (GMM): Then Gaussian Mixture Model(GMM) is used for modeling the foreground and the background. Then, in accordance with the data provided by the user, the GMM learns and creates labels for the unknown pixels and each pixel is clustered in terms of color statistics.

Graph Generation: A graph is generated from this pixel distribution where the pixels are considered as nodes and two additional nodes are added that is the Source node and Sink node. All the foreground pixels are connected to the Source node and every Background pixel is connected to the Sink node.

The weights of edges connecting pixels to the Source node and to the End node are defined by the probability of a pixel being in the foreground or in the background.

If huge dissimilarity is found in pixel color, the low weight is assigned to that edge:

Graph Segmentation Algorithm: Then the algorithm is applied to segment the graph. The algorithm segments the graph into two, separating the source node and the sink node with the help of a cost function which is the sum of all weights of the edges that are segmented.

Foreground-Background Labeling: After the segmentation, the pixels that are connected to the Source node is labeled as foreground and those pixels which are connected to the Sink node is labeled as background.

This process is done for multiple iterations as specified by the user. This gives us the extracted foreground.

Python | Foreground Extraction in an Image using Grabcut Algorithm

In this article we’ll discuss an efficient method of foreground extraction from the background in an image. The idea here is to find the foreground, and remove the background. 

Similar Reads

GrabCut Algorithm for Image Segmentation

GrabCut is an interactive image segmentation algorithm that was introduced by Carsten Rother, Vladimir Kolmogorov, and Andrew Blake in 2004. It is a graph-cut-based algorithm designed to segment an image into foreground and background regions, making it particularly useful for applications like image editing and object recognition....

How does GrabCut Algorithm work for Image Segmentation ?

Region Drawing: In this algorithm, the region is drawn in accordance with the foreground, a rectangle is drawn over it. This is the rectangle that encases our main object. The region coordinates are decided over understanding the foreground mask but imperfect segmentation may occur, marked for manual correction....

GrabCut in OpenCV

The function used here is cv2.grabCut()...

Conclusion

...

GrabCut Algorithm for Image Segmentation – FAQs

GrabCut, an effective image segmentation algorithm, provides efficient foreground extraction. Despite limitations, GrabCut serves as a practical solution in applications....

Contact Us