This is a great question about image compression using Singular Value Decomposition (SVD). Let me provide a comprehensive explanation.
Image Compression using SVD
1. SVD Decomposition Basics
For an m×n matrix A (representing an image), SVD decomposes it as:
A = UΣV^T
Where:
- U: m×m orthogonal matrix (left singular vectors)
- Σ: m×n diagonal matrix with singular values σ₁ ≥ σ₂ ≥ ... ≥ σᵣ > 0 (r = rank(A))
- V: n×n orthogonal matrix (right singular vectors)
2. Rank-k Approximation
The truncated SVD gives:
A_k = U_k Σ_k V_k^T
Where:
- U_k: m×k (first k columns of U)
- Σ_k: k×k (top-left k×k block of Σ)
- V_k: n×k (first k columns of V)
3. Image Compression
For grayscale images:
- Original storage: m×n values
- Compressed storage: k(m+n+1) values
- Compression ratio: mn / (k(m+n+1))
For color images: Compress each channel separately
4. Why this is optimal in Frobenius norm
Let me prove this is the best rank-k approximation in Frobenius norm.
Theorem: Among all rank-k matrices, A_k = U_k Σ_k V_k^T minimizes ||A - B||_F
Proof:
Given any rank-k matrix B, we want to show:
||A - A_k||_F ≤ ||A - B||_F
First, note that:
||A - A_k||_F² = Σᵢ₌ₖ₊₁ʳ σᵢ²
This follows because the Frobenius norm of the difference equals the sum of squared singular values that were discarded—the orthogonality of U and V preserves this norm, leaving only the contribution from the truncated singular values.
The Eckart-Young theorem establishes that this truncated SVD is optimal: among all rank-k approximations to A, the one formed by keeping the first k singular values and vectors minimizes the Frobenius norm error, achieving ||A - A_k||_F = √(Σᵢ₌ₖ₊₁ʳ σᵢ²).
This optimality stems from several key properties. The singular values themselves encode the relative importance of each direction—keeping the largest k values preserves maximum information content. The Frobenius norm remains invariant under orthogonal transformations, which allows us to analyze the problem in the transformed coordinate system where the structure becomes transparent. Additionally, each step of removing a singular value produces the smallest possible increase in reconstruction error, making the greedy selection of top-k values optimal overall.
To formalize this, the Eckart-Young theorem establishes that for any competing rank-k approximation B, the truncated SVD satisfies ||A - A_k||_F ≤ ||A - B||_F. This follows because the singular values of A dominate those of any rank-k matrix through the Cauchy interlacing inequalities: σᵢ ≥ bᵢ for each i ≤ k. Since the rank of A - B must be at least r - k when B has rank k, the error from the truncated SVD cannot exceed that of any alternative rank-k approximation. The rank-k projection of A minimizes the Frobenius norm among all rank-k matrices. By the max-min principle, truncating the SVD at rank k produces the optimal low-rank approximation—keeping the k largest singular values preserves the most significant structure in the original matrix. Any alternative rank-k approximation would necessarily discard at least one of these dominant directions, introducing greater reconstruction error.
The singular values themselves quantify how much each direction contributes to the overall structure. In image data, these typically decay rapidly, with σ₁ substantially larger than σ₂, which is larger than σ₃, and so on. This rapid decay is what makes compression effective—the tail singular values contribute minimally to the image content, so discarding them produces negligible visual loss.
Image Compression Using SVD
Overview
SVD decomposes an image matrix A (m×n pixels) as:
A=UΣVT=∑i=1r
For rank-k compression, we truncate to the k largest singular values:
Ak=UkΣ
Compression Mechanism
Storage Comparison
| Representation | Storage |
|---|
| Original image | m·n values |
| Compressed (rank-k) | k(m+n+1) values |
| Compression ratio | m·n / [k(m+n+1)] |
Example: 512×512 image
- Original: 262,144 values
- k=50: 51,250 values → 5.1× compression
Why this works
Typical images have rapidly decaying singular values:
σ1≫σ2≫σ
Often σ₁ through σ₅₀ capture >95% of information!
Proof: Why SVD Truncation is Optimal in Frobenius Norm
The Eckart-Young Theorem
The rank-k truncation of SVD minimizes the Frobenius norm reconstruction error among all rank-k matrices.
Mathematical Proof
Claim: For any rank-k matrix B,
∥A−Ak∥F≤∥A−B
Proof:
Step 1: Express reconstruction error via singular values
∥A−Ak∥F2=
This is because:
∥A−Ak∥F
(Frobenius norm is orthogonal-invariant; the error comes purely from discarded singular values)
Step 2: Apply rank constraint to arbitrary B
For any rank-k matrix B:
rank(A−B)≥rank(A)−k=r−k
Therefore, A - B has at least (r-k) non-zero singular values.
Step 3: Use singular value interlacing
By the Cauchy interlacing inequalities:
∑i=1r−kσi
Thus:
∥A−B∥F2≥∑
QED ✓
Why Singular Values are the Right Measure
Information Content
The singular values quantify variance/energy in orthonormal directions:
σi=max∥x∥=1∥Av
- Large σᵢ: Direction vᵢ captures significant image structure
- Small σᵢ: Direction captures noise or subtle variations
- Truncating small values: Removes least important information first
Orthogonal Invariance
The Frobenius norm respects SVD structure:
∥A−B∥F=∥UT(A−
This means the optimal low-rank approximation depends only on singular values, not on specific pixel arrangements.
Example: Demonstration
import numpy as np
import matplotlib.pyplot as plt
from scipy.linalg import svd
# Load image
img = plt.imread('image.png') # Grayscale: shape (m, n)
# SVD decomposition
U, sigma, Vt = svd(img, full_matrices=False)
# Reconstruct with k singular values
def reconstruct(k):
return U[:,:k] @ np.diag(sigma[:k]) @ Vt[:k,:]
# Compare compressions
fig, axes = plt.subplots(1, 4, figsize=(16,4))
for idx, k in enumerate([10, 50, 150, len(sigma)]):
A_k = reconstruct(k)
error = np.linalg.norm(img - A_k, 'fro')
ratio = (img.size) / (k * (img.shape[0] + img.shape[1] + 1))
axes[idx].imshow(A_k, cmap='gray')
axes[idx].set_title(f'k={k}\nError: {error:.0f}, Ratio: {ratio:.1f}×')
plt.tight_layout()
plt.show()
# Singular value decay
plt.semilogy(sigma[:100])
plt.xlabel('Singular Value Index')
plt.ylabel('Magnitude (log scale)')
plt.title('Singular Value Decay')
plt.show()
Key Insights
| Property | Why it Matters |
|---|
| Rapid decay | Most σᵢ are tiny; high compression possible |
| Orthogonality | Directions U, V are uncorrelated; no redundancy |
| Greedy optimality | Removing smallest singular value minimizes loss |
| Universal | Works for any matrix type (images, video, etc.) |
Trade-offs
- ✅ Mathematically optimal (Frobenius norm)
- ✅ Simple and interpretable
- ❌ More computation than streaming methods
- ❌ Must store U, Σ, V^T (dense format)
- ❌ Other norms (spectral norm, L∞) have different optimal solutions