python - 寻找图像的 Rank K 近似值
问题描述
我正在编写一个函数来查找图像的等级近似值。当 K 等于 1 和 2 时,我设法让它工作,但我找不到制作通用函数的方法。此外,我通过调用 linalg.svd() 成功地创建了 U/Vh/s 变量。
对于 2 级,我做了这样的事情来组合图像,并且成功地总结了 SVD
rank1TotalOne = np.dstack((rank1Redone, rank1Greenone, rank1Blueone))
rank1TotalTwo = np.dstack((rank1Redtwo, rank1Greentwo, rank1Bluetwo))
plt.imshow((rank1TotalOne + rank1TotalTwo).astype(int))
现在我试图将它概括为这样的东西,但我的图像没有正确显示。
k = 10
rankTotal = 0
j = 0
for i in range(0, k):
while(j < k):
columnVect = UR[:, j].reshape(300,1)
rowVect = VhR.T[:,j].reshape(1, 200)
rank1Red = sR[j] * columnVect * rowVect
columnVect = UG[:, j].reshape(300,1)
rowVect = VhG.T[:,j].reshape(1,200)
rank1Green = sG[j] * columnVect * rowVect
columnVect = UB[:, j].reshape(300,1)
rowVect = VhB.T[:,j].reshape(1,200)
rank1Blue = sB[j] * columnVect * rowVect
rank1Total = rank1Total + np.dstack((rank1Red, rank1Green, rank1Blue))
rank1Total = rank1Total.astype(int)
j = j + 1
plt.imshow(rank1Total)
plt.show()
解决方案
我真的很笨,我刚刚注意到我的代码有一个 rank1Total 和 rankTotal 变量。
rankTotal = rankTotal + np.dstack((rank1Red, rank1Green, rank1Blue))
rankTotal = rankTotal.astype(int)
j = j + 1
plt.imshow(rankTotal)
plt.show()
我只需要从 rank1Total 到 rankTotal,这是因为 rankTotal 我希望将所有内容保存到。
推荐阅读
- xamarin.ios - Xamarin.iOS MT2002 无法解析 Xamarin 11.9.1 上的 BindingImplAttribute
- visual-studio-2015 - 用vs2015编译mfc程序出错
- oculus - Oculus Go 开发者模式 - 已成功安装 apk,但未在 Oculus 中显示
- c# - MVC ajax 正在返回部分布局而不是部分
- vba - 在邮件的 htmlbody 中包含 Excel 范围值
- html - React - 如何将字形图标对齐到最右边?
- css - 如何将绝对 div(内部包含一些内容)拉伸到其父 div?
- c++ - 避免警告:对“计数”的操作可能未定义 [-Wsequence-point]
- pyspark - spark:使用多个分隔符读取 csv
- javascript - 将 CSS 动态应用到 JSX 对象