Jubayer Hasan
Jubayer Hasan

Reputation: 77

Image reconstruction using eigen vector

I'm doing some image processing following PCA. I'm working with image recognition problem. Is there any way to reconstruct my images ( used for training ) using eigen vector/weight? I followed this procedure : https://onionesquereality.wordpress.com/2009/02/11/face-recognition-using-eigenfaces-and-distance-classifiers-a-tutorial/

Upvotes: 2

Views: 2599

Answers (1)

aerin
aerin

Reputation: 22694

When you have your principal components (PC), you can reduce your dimensionality by calculating the dot product with PCs and your data, like below.

def projectData(X, U, K):
    # Compute the projection of the data using only the top K eigenvectors 
    # in U (first K columns). 
    # X: data
    # U: Eigenvectors
    # K: your choice of dimension

    new_U = U[:,:K]
    return X.dot(new_U)

Now, how do we get the original data back? By projecting back onto the original space using the top K eigenvectors in U.

def recoverData(Z, U, K):
    # Compute the approximation of the data by projecting back onto 
    # the original space using the top K eigenvectors in U. 
    # Z: projected data

    new_U = U[:, :K]
    return Z.dot(new_U.T) # We can use transpose instead of inverse because U is orthogonal.

Upvotes: 2

Related Questions