Basis vectors built by pcabuildbasis() are orthonormal, i.e. elements of eigenFaces are always in [-1,+1]. These elements describe directions of spread of your dataset, but they do not contain offset/scaling information. For example, if you try to apply pcabuildbasis() to 1-dimensional dataset [1000,1001,1002] then you will get [+1] or [-1] as eigenvector. As you see - no offset information.
And you've misunderstood meaning of coeffs - this array is not array of coefficients. It is array of variances.
If you want to reproduce your matrix (just to make sure that basis was correctly built), your code should look like:
Code:
// here I assume that all elements were correctly initialized
pcabuildbasis(faces, numPixels, numFaces, info, coeffs, eigenFaces);
for (int face_to_reconstruct = 0; face_to_reconstruct<numFaces; ++face_to_reconstruct)
{
for(pixel = 0; pixel<numPixels; ++pixel)
reconstructed[pixel] = 0.0;
for (int eigenface = 0; eigenface<numPixels; ++eigenface)
{
// coefficient before eigenface
double coefficient = 0.0;
// calculate coefficient
for (int pixel = 0; pixel<numPixels; ++pixel)
coefficient += eigenFaces[pixel][eigenface]*faces[face_to_reconstruct];
// update reconstructed face
for (int pixel = 0; pixel<numPixels; ++pixel)
reconstructed[pixel] += eigenFaces[pixel][eigenface]*coefficient;
}
}
I may have some errors because I've never actually executed this code, but I hope that idea should be clear.