Search code examples
matlabimage-processingpcafeature-extraction

Can i find PCA of a single image? - MATLAB


I am doing face recognition using PCA and SVM. My training set has an array of 400 images on which i have performed PCA and mapped the data into the eigenspace. Now for testing i have only a single image whose principal components i need to extract to match with the previously extracted features. But any algorithm of PCA i use or even the inbuilt command (princomp) i am getting dimension error. Cause PCA requires forming the eigenspace and projecting data onto this space, how do i form the eigenspace for a single image?


Solution

  • You should use the same eigenspace obtained with the training data.

    Here you have a tutorial that explains it very well. These are the main steps:

    Training:

    % step: 1: find the mean image
    mean_face = mean(images, 2);
    % step 3 : calculate the eigenvectors and eigenvalues
    [evectors, score, evalues] = princomp(images');
    

    Testing:

    % calculate the feture vector
    feature_vec = evectors' * (input_image(:) - mean_face);
    

    As you can see evectorsand mean_face were coputed during the training stage.