This project performs background–foreground separation in video sequences using three different matrix decomposition methods:
- PCP (Principal Component Pursuit) – convex RPCA
- GoDec – fast non-convex approximation
- ADMM-based RPCA – augmented Lagrangian optimization
The goal is to decompose a video into:
[ D = L + S ]
where:
- L = low-rank background
- S = sparse foreground (moving objects)
A video is loaded frame by frame, converted to grayscale, resized, vectorized, and stored as columns of the data matrix. Each method then performs Low-Rank + Sparse decomposition to extract the static background and dynamic foreground.
The project includes full visualization for all frames:
- Original frame
- Background estimated by each method
- Foreground extracted by each method
Solves the convex optimization problem:
[ \min_{L,S} |L|_* + \lambda |S|_1 \quad \text{s.t. } D = L + S ]
- Nuclear norm → promotes low rank
- L1 norm → promotes sparsity
- Very accurate but computationally slow
- Ideal for high-quality separation
In the code:
[L2, S2] = PCP(D, lambda_pcp, tol);Fast non-convex method using alternating projections:
- Projection onto low-rank matrices (rank ≤ r)
- Projection onto sparse matrices (cardinality ≤ k)
Model:
[ \min_{L,S} |D - L - S|_F^2 ]
- Much faster than PCP
- Good approximation for long videos
- Requires choosing rank r and sparsity k
In the code:
[L3, S3, ~, ~] = GoDec(D, rank_godec, card, power);Uses the augmented Lagrangian:
[ \mathcal{L}*\beta(L,S,\Lambda)= |L|** + \lambda|S|_1 + \frac{\beta}{2}|D - L - S + \frac{1}{\beta}\Lambda|_F^2 ]
Updates:
- SVT (Singular Value Thresholding) for ( L )
- Soft-thresholding for ( S )
- Dual update for ( \Lambda )
A good compromise between PCP accuracy and GoDec speed.
In the code:
[L4, S4, ~, ~] = RPCA_ADMM(D, lambda_admm, p_admm, maxIter_admm);-
Read video
-
Convert each frame to grayscale
-
Resize frames
-
Vectorize each frame
-
Construct matrix (D)
-
Run:
- PCP
- GoDec
- ADMM
-
Display in real-time:
Original | PCP Background | GoDec Background | ADMM Background
| PCP Foreground | GoDec Foreground | ADMM Foreground