【问题标题】:Finding Rank K approximation of an Image寻找图像的 Rank K 近似值
【发布时间】:2019-07-27 14:19:19
【问题描述】:

我正在编写一个函数来查找图像的等级近似值。当 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()

【问题讨论】:

标签: python pandas numpy jupyter-notebook


【解决方案1】:

我真的很笨,我刚刚注意到我的代码有一个 rank1Total 和 rankTotal 变量。

rankTotal = rankTotal + np.dstack((rank1Red, rank1Green, rank1Blue))
rankTotal = rankTotal.astype(int)
j = j + 1

plt.imshow(rankTotal)
plt.show()

我只需要从 rank1Total 转到 rankTotal,这是因为 rankTotal 我希望将所有内容保存到。

【讨论】:

    猜你喜欢
    • 2015-06-09
    • 1970-01-01
    • 2015-02-13
    • 2018-11-28
    • 2010-09-09
    相关资源
    最近更新 更多