Skip to content
ExtendedSource checked

GrabCut

Segments foreground from background using graph cuts and color models.

Quick Facts

Compact metadata for implementation and discovery.

Category
Image Processing
Difficulty
Advanced
Family
Image Segmentation
Tier
Extended
Status
Verified
Review
Source Checked
Sources
2
Formulas
1
Relationships
1
Code example
Ready
Visualization
Ready

Overview

GrabCut alternates between estimating foreground/background color distributions and solving a graph-cut labeling problem.

Core Concepts

foreground modelbackground modelgraph cutiterative labeling

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(pixels)

Average

O(iterations * graph_cut)

Worst

O(iterations * graph_cut)

Space

O(pixels)

When to Use

  • Use when image enhancement needs foreground model.
  • Use when the input matches the assumptions behind image Segmentation.

When Not to Use

  • Avoid when image noise, lighting, or scale breaks the algorithm's assumptions.
  • Avoid when a simpler algorithm gives the required result with less setup.

What It Does

  • Segments foreground from background using graph cuts and color models
  • Uses foreground model and background model to guide the work.
  • Produces processed image.

Use Cases

  • Image enhancement
  • Feature extraction
  • Segmentation and motion analysis

Inputs

  • Image or image sequence
  • Kernel, threshold, or model parameters

Outputs

  • Processed image
  • Mask
  • Feature map or motion field

Key Formulas (1)

Segmentation energy

E(labeling) = datacost + smoothnesscost
E(labeling) = data_cost + smoothness_cost

Balances color-model fit with boundary smoothness.

Pseudocode

  1. 1.Prepare the inputs and state needed for GrabCut.
  2. 2.Apply the foreground model step while the stopping condition has not been met.
  3. 3.Update intermediate state and discard invalid candidates.
  4. 4.Return processed image.

Canonical Example

Input
GrabCut input with a small representative case
Output
Processed image
Explanation
GrabCut applies foreground model to produce processed image.

Implementation Notes

  • Handle borders and pixel coordinate conventions consistently.
  • Keep the foreground model step separate enough to test independently.

Common Pitfalls

  • Applying operations in the wrong color space can distort the result.
  • Forgetting to check edge cases can make GrabCut look correct on only ideal inputs.

Interactive Mechanism Walkthrough

Spatial Primitive & Sweep-Line Canvas

Show the source image beside masks, filters, or motion vectors produced by the algorithm.

GrabCut mechanism walkthrough step 1 of 4
Step 1 of 4: Prepare the inputs and state needed for GrabCut.
image-processing-mechanism

Notes

GrabCut should be used with the assumptions and tradeoffs of image Segmentation in mind.

Sources (2)

What each reference supports for this entry.

GrabCut

Paper

Original GrabCut reference for iterative graph-cut foreground extraction and border matting.

Open source

Computer Vision: Algorithms and Applications

Book

Computer-vision reference supporting GrabCut feature extraction, image registration, segmentation, or multiscale image-analysis workflow.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

GrabCut and watershed segmentation are interactive or region-based alternatives for image segmentation.

Tags

Image ProcessingSegmentationGraphOptimization