[Numpy-discussion] PCA on set of face images

Peter Skomoroch peter.skomoroch at gmail.com
Fri Feb 29 14:57:18 EST 2008


Forgot the url:

http://www.cis.hut.fi/Opinnot/T-61.2010/harjoitustyo_en07.shtml

On Fri, Feb 29, 2008 at 2:56 PM, Peter Skomoroch <peter.skomoroch at gmail.com>
wrote:

> Here is the page I referenced for the octave version ... it includes
> examples very similar to what you want.  I will be posting a very similar
> example in Python later this month.
>
> I don't have any Python code on hand for the Petland paper, but I think
> matlab example should be easy to translate to scipy/matplotlib using the
> montage function:
>
> load faces.mat
> %Form covariance matrix
> C=cov(faces');
> %build eigenvectors and eigenvalues
> [E,D] = eig(C);
> %sort based on eigenvalue
> [B,index] = sortrows(D');
> E2=E';
> E2(index,:)';
> eigensorted=E2(index,:)';
> %show  eigenfaces
> clear Z;
> for i=1:length(eigensorted)
>    Z(:,:,1,i)=reshape(eigensorted(:,i)-1.5*min(min(min(eigensorted))),
> 19,19);
> end
> montage(Z)
> %show top 16 eigenfaces
>
> clear Z;
> for i=1:16
>    Z(:,:,1,i)=reshape(eigensorted(:,i)-min(min(min(eigensorted))), 19,19);
> end
> montage(Z)
>
>
>
>
> On Fri, Feb 29, 2008 at 2:50 PM, Peter Skomoroch <
> peter.skomoroch at gmail.com> wrote:
>
> > RoyG,
> >
> > The timing of your question couldn't be better, I just did an blog post
> > on this (I also plugged scipy and the EPD):
> >
> >
> > http://www.datawrangling.com/python-montage-code-for-displaying-arrays.html
> >
> > The code basically replicates the matlab montage() function and approach
> > to handling grayscale images using matplotlib.
> >
> > -Pete
> >
> >
> > On Fri, Feb 29, 2008 at 2:15 PM, devnew at gmail.com <devnew at gmail.com>
> > wrote:
> >
> > > hi guys
> > > I have a set of face images with which i want to do face recognition
> > > using Petland's PCA method.I gathered these steps from their docs
> > >
> > > 1.represent  matrix of face images data
> > > 2.find the adjusted matrix by substracting the mean face
> > > 3.calculate covariance matrix (cov=A* A_transpose)  where A is from
> > > step2
> > > 4.find eigenvectors and select those with highest eigenvalues
> > > 5.calculate facespace=eigenvectors*A
> > >
> > >
> > > when it comes to implementation i have doubts as to how  i should
> > > represent the matrix of face images?
> > > using PIL image.getdata() i can make an array of each greyscale image.
> > > Should the matrix be like each row contains an array representing an
> > > image? That will make a matrix with rows=numimages and
> > > columns=numpixels
> > >
> > > cavariancematrix =A *A_transpose will create a square matrix of
> > > shape(numimages,numimages)
> > > Using numpy.linalg.eigh(covariancematrix) will give eigenvectors of
> > > same shape as the covariance matrix.
> > >
> > > I would like to know if this is the correct way to do this..I have no
> > > big expertise in linear algebra  so i would be grateful if someone can
> > > confirm the right way of doing this
> > >
> > > RoyG
> > > _______________________________________________
> > > Numpy-discussion mailing list
> > > Numpy-discussion at scipy.org
> > > http://projects.scipy.org/mailman/listinfo/numpy-discussion
> > >
> >
> >
> >
> > --
> > Peter N. Skomoroch
> > peter.skomoroch at gmail.com
> > http://www.datawrangling.com
>
>
>
>
> --
> Peter N. Skomoroch
> peter.skomoroch at gmail.com
> http://www.datawrangling.com
>



-- 
Peter N. Skomoroch
peter.skomoroch at gmail.com
http://www.datawrangling.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20080229/473c8ecc/attachment.html>


More information about the NumPy-Discussion mailing list