This project implements the GrabCut algorithm for foreground segmentation and utilizes Poisson Blending for background replacement. The goal is to accurately segment a foreground object from an image and seamlessly blend it with a new background, preserving texture and color.
This repository contains the implementation of both GrabCut and Poisson Blending algorithms, including code, example images, and a detailed report on the methodology and results.
-
Initialization of GMMs:
- Initialize Gaussian Mixture Models (GMMs) for foreground and background using K-means clustering.
-
Update GMMs:
- Calculate and update mean, covariance, and weights of GMM components based on the current mask.
-
Min-Cut Calculation:
- Build a graph using the mask and energy terms, then compute the min-cut to segment the image.
-
Mask Update:
- Update the mask based on the min-cut results.
-
Convergence Check:
- Determine if the energy value has stabilized to a minimum.
-
Evaluation Metric:
- Evaluate segmentation accuracy and Jaccard similarity against ground truth.
-
Laplacian Operator Calculation:
- Compute the Laplacian of the source image.
-
Solve Poisson Equation:
- Solve the Poisson equation to blend the source and target images.
-
Blend and Save Image:
- Blend the foreground object with the new background and save the result.
A comprehensive report on the methodology and results can be found here.
data/imgs/
├── ... (input images)
data/seg_GT/
├── ... (ground truth binary images)
data/bg/
├── ... (background images)
data/bboxes/
├── ... (bounding boxes as txt files)
report_examples/
├── ... (example images and a detailed report)
grabcut.py
poisson_blend.py
README.md