confusion about eigenvector
i all I am learning PCA method by reading up Turk&Petland papers etc while trying out PCA on a set of greyscale images using python, and numpy I tried to create eigenvectors and facespace. i have facesarray--- an NXP numpy.ndarray that contains data of images N=numof images,P=pixels in an image avgarray --1XP array containing avg value for each pixel adjustedfaces=facesarray-avgarray adjustedmatrix=matrix(adjustedfaces) adjustedmatrix_trans=adjustedmatrix.transpose() covariancematrix =adjustedmatrix*adjustedmatrix_trans evalues,evect=eigh(covariancematrix) after sorting such that most significant eigenvectors are selected. evectmatrix is now my eigenvectors matrix here is a sample using 4X3 greyscale images evalues [ -1.85852801e-13 6.31143639e+02 3.31182765e+03 5.29077871e+03] evect [[ 0.5 -0.06727772 0.6496399 -0.56871936] [ 0.5 -0.77317718 -0.37697426 0.10043632] [ 0.5 0.27108233 0.31014514 0.76179023] [ 0.5 0.56937257 -0.58281078 -0.29350719]] evectmatrix (sorted according to largest evalue first) [[-0.56871936 0.6496399 -0.06727772 0.5 ] [ 0.10043632 -0.37697426 -0.77317718 0.5 ] [ 0.76179023 0.31014514 0.27108233 0.5 ] [-0.29350719 -0.58281078 0.56937257 0.5 ]] then i can create facespace by facespace=evectmat*adjustedfaces till now i 've been following the steps as mentioned in the PCA tutorial(by Lindsay smith & others) what i want to know is that in the above evectmatrix is each row ([-0.56871936 0.6496399 -0.06727772 0.5 ] etc) an eigenvector? or does a column in the above matrix represent an eigenvector? to put it differently, should i represent an eigenvector by evectmatrix[i] or by (get_column_i_of(evectmatrix)).transpose() if someone can make this clear please do D
Hi, If your images are 4x3, your eigenvector must be 12 long. Matthieu 2008/2/28, devnew@gmail.com <devnew@gmail.com>:
i all I am learning PCA method by reading up Turk&Petland papers etc while trying out PCA on a set of greyscale images using python, and numpy I tried to create eigenvectors and facespace.
i have facesarray--- an NXP numpy.ndarray that contains data of images N=numof images,P=pixels in an image avgarray --1XP array containing avg value for each pixel adjustedfaces=facesarray-avgarray adjustedmatrix=matrix(adjustedfaces) adjustedmatrix_trans=adjustedmatrix.transpose() covariancematrix =adjustedmatrix*adjustedmatrix_trans evalues,evect=eigh(covariancematrix)
after sorting such that most significant eigenvectors are selected. evectmatrix is now my eigenvectors matrix
here is a sample using 4X3 greyscale images
evalues [ -1.85852801e-13 6.31143639e+02 3.31182765e+03 5.29077871e+03] evect [[ 0.5 -0.06727772 0.6496399 -0.56871936] [ 0.5 -0.77317718 -0.37697426 0.10043632] [ 0.5 0.27108233 0.31014514 0.76179023] [ 0.5 0.56937257 -0.58281078 -0.29350719]]
evectmatrix (sorted according to largest evalue first) [[-0.56871936 0.6496399 -0.06727772 0.5 ] [ 0.10043632 -0.37697426 -0.77317718 0.5 ] [ 0.76179023 0.31014514 0.27108233 0.5 ] [-0.29350719 -0.58281078 0.56937257 0.5 ]]
then i can create facespace by facespace=evectmat*adjustedfaces
till now i 've been following the steps as mentioned in the PCA tutorial(by Lindsay smith & others) what i want to know is that in the above evectmatrix is each row ([-0.56871936 0.6496399 -0.06727772 0.5 ] etc) an eigenvector? or does a column in the above matrix represent an eigenvector? to put it differently, should i represent an eigenvector by evectmatrix[i] or by (get_column_i_of(evectmatrix)).transpose()
if someone can make this clear please do D _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
-- French PhD student Website : http://matthieu-brucher.developpez.com/ Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn : http://www.linkedin.com/in/matthieubrucher
On Feb 28, 1:27 pm, "Matthieu Brucher" wrote
If your images are 4x3, your eigenvector must be 12 long.
hi thanx for reply i am using 4 images each of size 4X3 the covariance matrix obtained from adjfaces*faces_trans is 4X4 in size and that produces the evalues and eigenvectors given here evalues,evect=eigh(covarmat) i will give the data i used facemat (ndarray from data of 4 images each4X3) [[ 173. 87. 88. 163. 167. 72. 75. 159. 170. 101. 88. 165.] [ 158. 103. 115. 152. 138. 58. 81. 153. 126. 68. 73. 143.] [ 180. 87. 107. 180. 167. 65. 86. 182. 113. 41. 55. 143.] [ 155. 117. 128. 147. 147. 70. 93. 146. 153. 65. 93. 155.]] avgvals [ 166.5 98.5 109.5 160.5 154.75 66.25 83.75 160. 140.5 68.75 77.25 151.5 ] adjfaces=matrix(facemat-avgvals) [[ 6.5 -11.5 -21.5 2.5 12.25 5.75 -8.75 -1. 29.5 32.25 10.75 13.5 ] [ -8.5 4.5 5.5 -8.5 -16.75 -8.25 -2.75 -7. -14.5 -0.75 -4.25 -8.5 ] [ 13.5 -11.5 -2.5 19.5 12.25 -1.25 2.25 22. -27.5 -27.75 -22.25 -8.5 ] [-11.5 18.5 18.5 -13.5 -7.75 3.75 9.25 -14. 12.5 -3.75 15.75 3.5 ]] faces_trans =adjfaces.transpose() [[ 6.5 -8.5 13.5 -11.5 ] [-11.5 4.5 -11.5 18.5 ] [-21.5 5.5 -2.5 18.5 ] [ 2.5 -8.5 19.5 -13.5 ] [ 12.25 -16.75 12.25 -7.75] [ 5.75 -8.25 -1.25 3.75] [ -8.75 -2.75 2.25 9.25] [ -1. -7. 22. -14. ] [ 29.5 -14.5 -27.5 12.5 ] [ 32.25 -0.75 -27.75 -3.75] [ 10.75 -4.25 -22.25 15.75] [ 13.5 -8.5 -8.5 3.5 ]] covarmat =adjfaces * faces_trans [[ 3111.8125 -1080.4375 -1636.4375 -394.9375] [-1080.4375 901.3125 -114.6875 293.8125] [-1636.4375 -114.6875 3435.3125 -1684.1875] [ -394.9375 293.8125 -1684.1875 1785.3125]] evalues,evectors=eigh(covarmat) evalues [ -1.85852801e-13 6.31143639e+02 3.31182765e+03 5.29077871e+03] evectors [[ 0.5 -0.06727772 0.6496399 -0.56871936] [ 0.5 -0.77317718 -0.37697426 0.10043632] [ 0.5 0.27108233 0.31014514 0.76179023] [ 0.5 0.56937257 -0.58281078 -0.29350719]] newevectmatrix [[-0.56871936 0.6496399 -0.06727772 0.5 ] [ 0.10043632 -0.37697426 -0.77317718 0.5 ] [ 0.76179023 0.31014514 0.27108233 0.5 ] [-0.29350719 -0.58281078 0.56937257 0.5 ]] i am not getting the eigenvector of length 12 as you said pls tell me if i am doing sthing wrong D
OK, what you are getting are not the eigenvectors of you data, but the eigenvectors of the transposition of your data (I suppose). You have two options : - either you make an eigen analysis of your data and get 12 eigenvectors - either you make an eigen analysis of the transposition of your data and then you must get the 4 eignevectors into your original space (I don't remember the exact equations to do thge latter). Matthieu 2008/2/28, devnew@gmail.com <devnew@gmail.com>:
On Feb 28, 1:27 pm, "Matthieu Brucher" wrote
If your images are 4x3, your eigenvector must be 12 long.
hi thanx for reply i am using 4 images each of size 4X3 the covariance matrix obtained from adjfaces*faces_trans is 4X4 in size and that produces the evalues and eigenvectors given here evalues,evect=eigh(covarmat)
i will give the data i used
facemat (ndarray from data of 4 images each4X3) [[ 173. 87. 88. 163. 167. 72. 75. 159. 170. 101. 88. 165.] [ 158. 103. 115. 152. 138. 58. 81. 153. 126. 68. 73. 143.] [ 180. 87. 107. 180. 167. 65. 86. 182. 113. 41. 55. 143.] [ 155. 117. 128. 147. 147. 70. 93. 146. 153. 65. 93. 155.]] avgvals [ 166.5 98.5 109.5 160.5 154.75 66.25 83.75 160. 140.5 68.75 77.25 151.5 ]
adjfaces=matrix(facemat-avgvals) [[ 6.5 -11.5 -21.5 2.5 12.25 5.75 -8.75 -1. 29.5 32.25 10.75 13.5 ] [ -8.5 4.5 5.5 -8.5 -16.75 -8.25 -2.75 -7. -14.5 -0.75 -4.25 -8.5 ] [ 13.5 -11.5 -2.5 19.5 12.25 -1.25 2.25 22. -27.5 -27.75 -22.25 -8.5 ] [-11.5 18.5 18.5 -13.5 -7.75 3.75 9.25 -14. 12.5 -3.75 15.75 3.5 ]]
faces_trans =adjfaces.transpose() [[ 6.5 -8.5 13.5 -11.5 ] [-11.5 4.5 -11.5 18.5 ] [-21.5 5.5 -2.5 18.5 ] [ 2.5 -8.5 19.5 -13.5 ] [ 12.25 -16.75 12.25 -7.75] [ 5.75 -8.25 -1.25 3.75] [ -8.75 -2.75 2.25 9.25] [ -1. -7. 22. -14. ] [ 29.5 -14.5 -27.5 12.5 ] [ 32.25 -0.75 -27.75 -3.75] [ 10.75 -4.25 -22.25 15.75] [ 13.5 -8.5 -8.5 3.5 ]] covarmat =adjfaces * faces_trans [[ 3111.8125 -1080.4375 -1636.4375 -394.9375] [-1080.4375 901.3125 -114.6875 293.8125] [-1636.4375 -114.6875 3435.3125 -1684.1875] [ -394.9375 293.8125 -1684.1875 1785.3125]]
evalues,evectors=eigh(covarmat)
evalues [ -1.85852801e-13 6.31143639e+02 3.31182765e+03 5.29077871e+03]
evectors
[[ 0.5 -0.06727772 0.6496399 -0.56871936] [ 0.5 -0.77317718 -0.37697426 0.10043632] [ 0.5 0.27108233 0.31014514 0.76179023] [ 0.5 0.56937257 -0.58281078 -0.29350719]]
newevectmatrix
[[-0.56871936 0.6496399 -0.06727772 0.5 ] [ 0.10043632 -0.37697426 -0.77317718 0.5 ] [ 0.76179023 0.31014514 0.27108233 0.5 ] [-0.29350719 -0.58281078 0.56937257 0.5 ]]
i am not getting the eigenvector of length 12 as you said pls tell me if i am doing sthing wrong
D _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
-- French PhD student Website : http://matthieu-brucher.developpez.com/ Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn : http://www.linkedin.com/in/matthieubrucher
On Thu, Feb 28, 2008 at 8:17 AM, devnew@gmail.com <devnew@gmail.com> wrote:
i all I am learning PCA method by reading up Turk&Petland papers etc while trying out PCA on a set of greyscale images using python, and numpy I tried to create eigenvectors and facespace.
i have facesarray--- an NXP numpy.ndarray that contains data of images N=numof images,P=pixels in an image avgarray --1XP array containing avg value for each pixel adjustedfaces=facesarray-avgarray adjustedmatrix=matrix(adjustedfaces) adjustedmatrix_trans=adjustedmatrix.transpose() covariancematrix =adjustedmatrix*adjustedmatrix_trans evalues,evect=eigh(covariancematrix)
after sorting such that most significant eigenvectors are selected. evectmatrix is now my eigenvectors matrix
here is a sample using 4X3 greyscale images
evalues [ -1.85852801e-13 6.31143639e+02 3.31182765e+03 5.29077871e+03] evect [[ 0.5 -0.06727772 0.6496399 -0.56871936] [ 0.5 -0.77317718 -0.37697426 0.10043632] [ 0.5 0.27108233 0.31014514 0.76179023] [ 0.5 0.56937257 -0.58281078 -0.29350719]]
evectmatrix (sorted according to largest evalue first) [[-0.56871936 0.6496399 -0.06727772 0.5 ] [ 0.10043632 -0.37697426 -0.77317718 0.5 ] [ 0.76179023 0.31014514 0.27108233 0.5 ] [-0.29350719 -0.58281078 0.56937257 0.5 ]]
then i can create facespace by facespace=evectmat*adjustedfaces
till now i 've been following the steps as mentioned in the PCA tutorial(by Lindsay smith & others) what i want to know is that in the above evectmatrix is each row ([-0.56871936 0.6496399 -0.06727772 0.5 ] etc) an eigenvector? or does a column in the above matrix represent an eigenvector?
The eigenvectors are in columns. To ensure yourself, look at the last constant column (of 0.5's) corresponding to the zero-eigenvalue. This id due to the initial column centering.
to put it differently, should i represent an eigenvector by evectmatrix[i] or by (get_column_i_of(evectmatrix)).transpose()
if someone can make this clear please do D _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
BTW: If your data is not extreme these simple steps would also result in what you want (Not tested): ------------- from scipy import linalg facearray-=facearray.mean(0) #mean centering u, s, vt = linalg.svd(facearray, 0) scores = u*s facespace = vt.T # reconstruction: facearray ~= dot(scores, facespace.T) explained_variance = 100*s.cumsum()/s.sum() # here is how to reconstruct an `eigen-image` from the first component # You may want to ensure this as it depends on how you created the facearray face_image0 = facespace[:,0].reshape(4,3) ----------- In case you have a large dataset (many pixels *and* many images) you may look into using the arpack eigensolver for efficiency (located in scikits and appearing in the upcomming release of scipy, 0.7) Arnar
Arnar wrote from scipy import linalg facearray-=facearray.mean(0) #mean centering u, s, vt = linalg.svd(facearray, 0) scores = u*s facespace = vt.T
hi Arnar when i do this i get these u =< 'numpy.core.defmatrix.matrix'> (4, 4) that matches the eigenvectors matrix in my previous data s=< 'numpy.ndarray'> (4,) and vt=<'numpy.core.defmatrix.matrix'> (4, 12) here scores=u*s causes a matrix not aligned error.. is there something wrong in the calculation? D
On Thu, Feb 28, 2008 at 3:41 PM, devnew@gmail.com <devnew@gmail.com> wrote:
Arnar wrote
from scipy import linalg facearray-=facearray.mean(0) #mean centering u, s, vt = linalg.svd(facearray, 0) scores = u*s facespace = vt.T
hi Arnar when i do this i get these u =< 'numpy.core.defmatrix.matrix'> (4, 4) that matches the eigenvectors matrix in my previous data s=< 'numpy.ndarray'> (4,) and vt=<'numpy.core.defmatrix.matrix'> (4, 12)
here scores=u*s causes a matrix not aligned error..
is there something wrong in the calculation?
D _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
This example assumes that facearray is an ndarray.(like you described in original post ;-) ) It looks like you are using a matrix. (u =< 'numpy.core.defmatrix.matrix'> (4, 4)) . This causes the u*s-broadcasting to fail. Try again, with: facearray = numpy.asarray(facearray), before calculation. Arnar
This example assumes that facearray is an ndarray.(like you described in original post ;-) ) It looks like you are using a matrix.
hi Arnar thanks .. a few doubts however 1.when i use say 10 images of 4X3 each u, s, vt = linalg.svd(facearray, 0) i will get vt of shape (10,12) can't i take this as facespace? why do i need to get the transpose? then i can take as eigface_image0= vt[0].reshape(imgwdth,imght) 2.this way (svd) is diff from covariance matrix method. if i am to do it using the later ,how can i get the eigenface image data? thanks for the help D
On Sat, Mar 1, 2008 at 8:27 AM, devnew@gmail.com <devnew@gmail.com> wrote:
This example assumes that facearray is an ndarray.(like you described in original post ;-) ) It looks like you are using a matrix.
hi Arnar thanks .. a few doubts however
1.when i use say 10 images of 4X3 each
u, s, vt = linalg.svd(facearray, 0) i will get vt of shape (10,12)
can't i take this as facespace? Yes, you may
why do i need to get the transpose? You dont need to. I did because then it would put the eigenvectors that span your column space as columns of the facespace array. I figured that would be easier for you, as that would be compatible with the use of eig (eigh) and matlab
then i can take as eigface_image0= vt[0].reshape(imgwdth,imght)
2.this way (svd) is diff from covariance matrix method.
No it is not. You may be fooled by the scaling though. I see from the post above, that there may be some confusion here about svd and eig on a crossproduct matrix :-) Essentially, if X is a column centered array of size (num_images, num_pixels): u, s, vt = linalg.svd(X), Then, the columns of u span the space of dot(X, X.T), the rows of vt span the space of dot(X.T, X) and s is a vector of scaling coefficients. Another way of seeing this is that u spans the column space of X, and vt spans the row space of X. So, for a third view, the columns of u are the eigenvectors of dot(X, X.T) and the rows of vt contains the eigenvectors of dot(X.T, X). Now, in your, `covariance method` you use eigh(dot(X, X.T)), where the eigenvectors would be exactly the same as u(the array) from an svd on X. In order to recover the facespace you use facespace=dot(X.T, u). This facespace is the same as s*vt.T, where s and vt are from the svd. In my example, the eigenvectors spanning the column space were scaled. I called this for scores: (u*s) In your computation the facespace gets scaled implicit. Where to put the scale is different from application to application and has no clear definition. I dont know if this made anything any clearer. However, a simple example may be clearer: ------- # X is (a ndarray, *not* matrix) column centered with vectorized images in rows # method 1: XX = dot(X, X.T) s, u = linalg.eigh(XX) reorder = s.argsort()[::-1] facespace = dot(X.T, u[:,reorder]) # method 2: u, s, vt = svd(X, 0) facespace2 = s*vt.T ------ This gives identical result. Please remember that eigenvector signs are arbitrary when comparing.
if i am to do it using the later ,how can i get the eigenface image data?
Just like I described before Arnar
Arnar wrote I dont know if this made anything any clearer. However, a simple example may be clearer: # X is (a ndarray, *not* matrix) column centered with vectorized images in rows # method 1: XX = dot(X, X.T) s, u = linalg.eigh(XX) reorder = s.argsort()[::-1] facespace = dot(X.T, u[:,reorder])
ok..this and # method 2: (ie svd()) returns same facespace ..and i can get eigenface images i read in some document on the topic of eigenfaces that 'Multiplying the sorted eigenvector with face vector results in getting the face-space vector' facespace=sortedeigenvectorsmatrix * adjustedfacematrix (when these are numpy.matrices ) that is why the confusion about transposing X inside facespace=dot(X.T,u[:,reorder]) if i make matrices out of sortedeigenvectors, adjustedfacematrix then i will get facespace =sortedeigenvectorsmatrix * adjustedfacematrix which has a different set of elements than that obtained by dot(X.T, u[:,reorder]). the result differs in some scaling factor? i couldn't get any clear eigenface images out of this facespace:-( D
i read in some document on the topic of eigenfaces that 'Multiplying the sorted eigenvector with face vector results in getting the face-space vector' facespace=sortedeigenvectorsmatrix * adjustedfacematrix (when these are numpy.matrices ) This will not work with numpy matrices.* is elementwise mult.
that is why the confusion about transposing X inside
facespace=dot(X.T,u[:,reorder])
if i make matrices out of sortedeigenvectors, adjustedfacematrix then i will get facespace =sortedeigenvectorsmatrix * adjustedfacematrix which has a different set of elements than that obtained by dot(X.T, u[:,reorder]).
No, they are the same. u[:, reorder] *is* the sortedeigenvectormatrix, and the transpose of a matrixproduct: (A*B).T == B.T*A, so your facespace is just the transpose of mine. I dont know why you are getting the end result wrong. Perhaps you are reshaping wrong? I'll try a complete example :-) Get example data: http://www.cs.toronto.edu/~roweis/data/frey_rawface.mat ----- import scipy as sp from matplotlib.pyplot import * fn = "frey_rawface.mat" data = sp.asarray(sp.io.loadmat(fn)['ff'], dtype='d').T data = data - data.mean(0) u, s, vt = sp.linalg.svd(data, 0) # plot the first 6 eigenimages for i in range(6): subplot(2,3,i+1), imshow(vt[i].reshape((28,20)), cmap=cm.gray) axis('image'), xticks([]), yticks([]) title("First 6 eigenfaces") ------ Arnar
ok..I coded everything again from scratch..looks like i was having a problem with matrix class when i used a matrix for facespace facespace=sortedeigenvectorsmatrix * adjustedfacematrix and trying to convert the row to an image (eigenface). by make_simple_image(facespace[x],"eigenimage_x.jpg",(imgwdth,imght)) .i was getting black images instead of eigenface images. def make_simple_image(v, filename,imsize): v.shape=(-1,) #change to 1 dim array im = Image.new('L', imsize) im.putdata(v) im.save(filename) i made it an array instead of matrix make_simple_image(asarray(facespace[x]),"eigenimage_x.jpg", (imgwdth,imght)) this produces eigenface images another observation, the eigenface images obtained are too dark,unlike the eigenface images generated by Arnar's code.so i examined the elements of the facespace row sample rows: [ -82.35294118, -82.88235294, -91.58823529 ,..., -66.47058824, -68.23529412, -60.76470588] .. [ 89.64705882 82.11764706 79.41176471 ..., 172.52941176 170.76470588 165.23529412] looks like these are signed ints.. i used another make_image() function that converts the elements def make_image(v, filename,imsize): v.shape = (-1,) #change to 1 dim array a, b = v.min(), v.max() span = max(abs(b), abs(a)) im = Image.new('L', imsize) im.putdata((v * 127. / span) + 128) im.save(filename) This function makes clearer images..i think the calculations convert the elements to unsigned 8-bit values (as pointed out by Robin in another posting..) ,i am wondering if there is a more direct way to get clearer pics out of the facespace row elements
I found this in my del.icio.us links, sorry I forgot to mention it at the time: http://www.owlnet.rice.edu/~elec301/Projects99/faces/code.html All the best On Thu, Mar 6, 2008 at 10:39 AM, devnew@gmail.com <devnew@gmail.com> wrote:
ok..I coded everything again from scratch..looks like i was having a problem with matrix class when i used a matrix for facespace facespace=sortedeigenvectorsmatrix * adjustedfacematrix and trying to convert the row to an image (eigenface). by make_simple_image(facespace[x],"eigenimage_x.jpg",(imgwdth,imght)) .i was getting black images instead of eigenface images.
def make_simple_image(v, filename,imsize): v.shape=(-1,) #change to 1 dim array im = Image.new('L', imsize) im.putdata(v) im.save(filename)
i made it an array instead of matrix make_simple_image(asarray(facespace[x]),"eigenimage_x.jpg", (imgwdth,imght)) this produces eigenface images
another observation, the eigenface images obtained are too dark,unlike the eigenface images generated by Arnar's code.so i examined the elements of the facespace row
sample rows: [ -82.35294118, -82.88235294, -91.58823529 ,..., -66.47058824, -68.23529412, -60.76470588] .. [ 89.64705882 82.11764706 79.41176471 ..., 172.52941176 170.76470588 165.23529412]
looks like these are signed ints..
i used another make_image() function that converts the elements def make_image(v, filename,imsize): v.shape = (-1,) #change to 1 dim array a, b = v.min(), v.max() span = max(abs(b), abs(a)) im = Image.new('L', imsize) im.putdata((v * 127. / span) + 128) im.save(filename)
This function makes clearer images..i think the calculations convert the elements to unsigned 8-bit values (as pointed out by Robin in another posting..) ,i am wondering if there is a more direct way to get clearer pics out of the facespace row elements
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
-- Peter N. Skomoroch peter.skomoroch@gmail.com http://www.datawrangling.com
------------- from scipy import linalg facearray-=facearray.mean(0) #mean centering u, s, vt = linalg.svd(facearray, 0) scores = u*s facespace = vt.T # reconstruction: facearray ~= dot(scores, facespace.T) explained_variance = 100*s.cumsum()/s.sum()
hi i am a newbie in this area of eigenface based methods..is this how to reconstruct face images from eigenfaces? facearray ~= dot(scores, facespace.T) i guess it translates to facearray = dot(sortedeigenvectorsmatrix , facespace) i tried it and it produces (from facearray) a set of images very similar(but dark and bit smudged around eyes,nose..) to the original set of face images.. oharry
participants (5)
-
Arnar Flatberg
-
devnew@gmail.com
-
harryos
-
Matthieu Brucher
-
Peter Skomoroch