MySVD.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:LinearAlgebra 作者: KeremTurgutlu 项目源码 文件源码
def SVD_Plot(imagepath_list):
    names = []
    sing_vals = []
    i = 0
    for image_path in imagepath_list:
        # READ IMAGE AND COMPUTE SYMMETRICAL MATRICES
        if type(image_path) == str:
            img = Image.open(image_path)
            img = img.convert("L")
            ncols = img.size[0]
            nrows = img.size[1]
            A = np.asarray(img.getdata()).reshape(nrows, ncols)
            names.append(image_path.split("/")[1].split(".")[0])
        else:
            i += 1
            A = image_path
            ncols = image_path.shape[1]
            nrows = image_path.shape[0]
            names.append("random %s" %i)
        Q1 = A.dot(A.T)
        Q2 = A.T.dot(A)


        # FIND V AND SINGULAR VALUES
        sigma_2, v = np.linalg.eig(Q2)
        singular_vals = np.sqrt(sigma_2)
        sing_vals.append(singular_vals)



    for i in range(len(imagepath_list)):
        val = sing_vals[i]
        maxi = max(val)
        mini = min(val)
        normalized_val = (val - mini) / (maxi - mini)
        plab.plot(normalized_val,label = names[i])

    plab.title("Singular Value Distributions")
    plab.xlabel("Singular Value Rank")
    plab.ylabel("Singular Value")
    plab.xlim(0, 30)
    plab.ylim(0, 1)
    plab.legend()
    plab.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号