# [Numpy-discussion] creating eigenface images

royG roygeorget@gmail....
Tue Mar 25 09:46:23 CDT 2008

```hi

98e/a66aa2565d4e6a24

i tried to create an application to create eigenfaces from a set of
jpeg images.I followed these steps after obtaining an ndarray of 17
images (ie 17 rows where each row is an image and a column is pixel
intensity values) and 18750 columns(since each image is 125X150)

faceimages is a (17,18750) ndarray
averageimage=average(faceimages,axis=0)
evals,evects=eigh(covmat)

reversedevalueorder=evals.argsort()[::-1]
sortedeigenvectors=evects[:,reversedevalueorder]

# now i have sortedeigenvectors of shape(17,17) .I assume that the
sort has made the first column to contain the most significant
eigenvector.Can someone confirm this assumption? If i do a transpose()
on it then i will get an ndarray with the first row as most
significant eigenvector?
sortedeigenvectors_rowwise=sortedeigenvectors.transpose()

# then i create a facespace where each row correspond to an eigenface

# i want to create the eigenface corresponding to most significant and
least significant eigenvectors.(I do this with the help of  a
createImage() function to put pixelvalues in an image)

besteigenvector=sortedeigenvectors_rowwise[0]
leasteigenvector=sortedeigenvectors_rowwise[numberofimgs-1] #which is
16
createImage(besteigenface,"eigenface0.jpg",(125,150))
createImage(leasteigenface,"eigenface16.jpg",(125,150))

roytechdumps.blogspot.com/).The leasteigenface  ie 'eigenface16.jpg'
is quite 'deteriorated' in appearance compared to the other.Is this
because of the

corresponding eigenvector containing least variations? can someone
explain this deterioration?

thanks

RG

by the way the function to create image is

def createImage(v, filename,imsize):
v.shape = (-1,)	#change to 1 dim array
a, b = v.min(), v.max()
im = Image.new('L', imsize)
sclaedarray=((v-a)* 255/(b - a))
im.putdata(scaledarray)
```