how to create eigenface image

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • harryos

    #1

    how to create eigenface image

    hi all
    I am new to python and 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=f acesarray-avgarray
    adjustedmatrix= matrix(adjusted faces)
    adjustedmatrix_ trans=adjustedm atrix.transpose ()
    covariancematri x =adjustedmatrix *adjustedmatrix _trans
    evalues,evect=e igh(covariancem atrix)

    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=evect mat*adjustedfac es

    what i want to know is how i can create eigenface images .
    when you mean an eigenvector ,is that a row of evectmatrix above? is
    evectmatrix[0] the eigenvector for first image and so on? I would
    appreciate if someone can make this clear.

    also
    when i tried to make an image by
    im=im = Image.new('L', (width,height))
    im.putdata(evec tmat[0])
    im.save("eigenf ace0.jpg")

    it created an image with all pixels dark with no details to see
    the same occurrs if i use
    im.putdata(face space[0])
    can someone tell me if i am doing it wrong..




Working...