The Singular Value Decomposition (SVD)
特征值分解,这个线性代数中的基本知识我们都不陌生。然而,其仅限于那些方阵。对于常见的rectangle矩阵,奇异值分解应用更为广泛,其已被广泛应用于压缩传输、降维等领域。
图像处理中的线性代数
- 一个灰度图像可以看作是一个具有灰度值的矩阵
- 当相邻像素相关时,图像就可以压缩,换言之一个完全随机的图像是不能压缩的
- SVD可以将一个矩阵分解成若干个秩为1的部分
- 和分别是是对称矩阵和的特征向量
对于一个秩为一的图像矩阵矩阵,和往往较大。如果我们使用秩一分解去表示,只需要个元素,远比小的多。这里,给出一个例子:
通常,高清显示屏分辨率为,以一秒传输帧RGB图像计算,一秒钟需要传输比特的数据。无疑,这样传输是及其耗时的,发射机跟不上节目进行的速度。因此,压缩传输是很有必要的。当压缩达到一定效果的时候,人眼是很难感受到细微的差别。
低秩图像举例
最容易压缩的图像是全黑或全白或全灰度不变的图像,假设,且:
- Example
通常我们不会存储或者传输
而只需要传输
30个数字变为11个数字,假设是的图像,降低的会更为明显。同样,如果我们提前定义了全1矩阵,图像处理可以非常快。
SVD的特征向量
SVD的使用两组特征向量表示和,即分别为对称矩阵和的特征向量。
- :左奇异向量的特征向量
- :右奇异向量的特征向量
有
The key point is not that images tend to have low rank. No: Images mostly have full rank. But they do have low effective rank. This means: Many singular values are small and can be set to zero. We transmit a low rank approximation [ref][1].
奇异值分解中的基和矩阵
- SVD为四个基本子空间生成和的标准正交基
- 使用这些基,就变成了一个对角矩阵和
- SVD(二基对角化)通常比特征值分解具有更加丰富的表征信息
- 可以对进行秩一分解,最大
对于一个秩为的矩阵, SVD使用两套基向量和,基矩阵和,它们给出了四个基本子空间
这些基向量是正交的,而且它们对进行了对角化
其中为矩阵的奇异值,所有的奇异值构成了一个对角阵。
由于所有的和是正交的,所以
于是
因此
将奇异值按照从大到小顺序排列,SVD就将按照重要性的顺序分解为个秩一部分,即
SVD应用广泛,可以用于
- Dimensionality reduction
- Eigenfaces
- Reducing noise
例如,降维例程[2]
# Listing 15
# Reading the image
mat = plt.imread("Picture.png")
# SVD
U, s, VT = LA.svd(mat)
Sigma = np.zeros((mat.shape[0], mat.shape[1]))
Sigma[:min(mat.shape[0], mat.shape[1]), :min(mat.shape[0], mat.shape[1])] = np.diag(s)
# Reconstruction of the matrix using the first 30 singular values
k = 30
mat_approx = U[:, :k] @ Sigma[:k, :k] @ VT[:k, :]
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10,8))
plt.subplots_adjust(wspace=0.3, hspace=0.2)
ax1.imshow(mat, cmap='gray')
ax1.set_title("Original image")
ax2.imshow(mat_approx, cmap='gray')
ax2.set_title("Reconstructed image using the \n first {} singular values".format(k))
plt.show()
参考资料
[1]Gilbert Strang, Chapter 7, Introduction to Linear Algebra, 5th Edition, 2016.: https://mp.weixin.qq.com/s?__biz=MzUyMTE2NDYxMQ==&mid=2247487192&idx=1&sn=1df5e64a26611b464e0830c3a8fc2db8&chksm=f9de0cf4cea985e2097b8df98aa8d71512286fe4030af02dbc052cf8851b3ef694963923fd29&token=760790189&lang=zh_CN#rd
[2]Understanding Singular Value Decomposition and its Application in Data Science: https://towardsdatascience.com/understanding-singular-value-decomposition-and-its-application-in-data-science-388a54be95d