6

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?

Sid
  • 249
  • 5
  • 16

1 Answers1

3

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.

lucidbrot
  • 5,378
  • 3
  • 39
  • 68
phyrox
  • 2,423
  • 15
  • 23
  • Phyrox , i don't want to compute the similarity, i want to train the SVM using the principal components. But i am not able to test the SVM, cause i don't know how to "project test image to the already formed eigenspace" – Sid Jan 28 '14 at 08:28
  • @Sid How do you compute your feature vector in the training stage? Please, post your code so we can help you better – phyrox Jan 28 '14 at 08:43
  • I was able to project the test image to the eigenspace. But i am encountering a bigger problem now. I have a "training set" of images. The projections of "face 1" to the eigenspace has to be labelled +1 and the projections of all the other faces to the eigenspace has to be labelled -1. I don't know how to do this. Any suggestions would be really helpful. – Sid Jan 29 '14 at 09:17
  • @Sid: Maybe using a separate array with the same order of your projections? If not, post a new question with your code and some sample data. – phyrox Jan 29 '14 at 10:06
  • I have asked the question - http://stackoverflow.com/questions/21426842/how-to-label-the-training-projections-obtained-by-pca-to-use-for-training-svm-fo – Sid Jan 29 '14 at 13:51
  • It would be really helpful if you looked at this question too- http://stackoverflow.com/questions/21427303/is-this-the-right-way-of-projecting-the-training-set-into-the-eigespace-matlab – Sid Jan 29 '14 at 13:59