图像的Python奇异值分解用于噪声滤波

2024-10-03 23:25:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个PCA脚本,它遍历一组图像,并将它们分解成按功率/重量排序的PC。据我所知,你想做M = U*S*V.T,我已经在下面做了。我切断了N处的数组,这是一个过滤掉所有下层PC的过滤器。但它似乎根本不起作用,并返回了明显不是PC的。我是否误解了数学?在

def PCA(cube_array, PCA_N=False, cutoff=1, verbatim=0):
    cube_shape_z, cube_shape_x, cube_shape_y = cube_array.shape
    n = 1
    M = cube_array.reshape(cube_array.shape[0],-1)


    U, s, Vt = np.linalg.svd(M, full_matrices=False)
    V = Vt.T
    S = np.diag(s)
    N = cutoff
    Mhat = np.dot(U[:, :N], np.dot(S[:N, :N], 
    V[:,:N].T)).reshape(cube_array.shape)
    return Mhat

Tags: 图像脚本falsenparraydotcutoffshape