提问人:Igor 提问时间:7/2/2023 最后编辑:desertnautIgor 更新时间:7/3/2023 访问量:73
图片尺寸缩小
Picture dimension reduction
问:
我需要通过奇异值分解来减少我的图片尺寸。
我已经看到了很多关于这个主题的来源。他们建议使用以下方法:
m, n = img.shape
U, S, V = np.linalg.svd(img)
#U.shape = m * m; S.shape = m * n; V.shape = n * n
img_cut = U[:, :x] @ np.diag(S[:x, :x]) @ V[:x, :]
这应该将图像的大小减小到 .但是图像的大小是相同的,因为 和 保持不变。我能做些什么?x
m * n
U.shape[0]
V.shape[1]
答:
正如你所意识到的,维度是相同的。
SVD 的原理是将矩阵分解为三部分。
通过仅使用前 x 个奇异向量和值,可以将数据点减少到维度。M=USV^T
x
为此,您只使用两个矩阵:
img_cut = U[:, :x] @ np.diag(S[:x, :x])
你同样可以用 V 来做到这一点,这是一种简化。 在考虑表格数据时,这样做不是减少特征,而是减少样本。
通过使用另一个矩阵,您可以重建原始数据 - 根据 x 会有一些误差。此重构数据是具有秩 x 的低秩近似值。
img_reconstructed = img_cut @ V[:x, :]
评论
U[:x, :x] @ np.diag(S[:x, :x]) @ V[:x,:x]
The SVD decomposition of a matrix A does not change the dimensions of A. And it wouldn't be a valuable thing to just reduce and image size, for, it would reduce the image quality. But we want to preserve image quality!
Instead, the SVD decomposition A = U Σ V^T means that we keep the same dimension for A, but we can replace three matrices U, Σ, V by much smaller matrices U_r, \Sigma_r, V_r which require much less numbers to write, but the product A_r = U_r Σ_r V_r^T of which is very close to our original matrix A.
These lecture notes explain the thing in detail: https://www.researchgate.net/publication/318066716_Linear_Algebra_Theory_and_Algorithms?o=Linear_Algebra
In particular, please see Section 38.2 and Section 41.1 (this section deals with images exactly!).
上一个:具有惊喜SVD的推荐算法
评论
[1,2,3,4,5,6,7,8]
0,1,0,1,0,1,0,1
1,3,3,5,5,7,7,9
[1,1]
n