In this assignment, you'll implement the Eigenface algorithm for face recognition from this paper . I have typed up an additional writeup on PCA here . A common approach to recognition is utilizing a nearest neighbor framework. Here, images are represented as points in a high-dimensional vector space. One recognizes a query face by finding the closest labelled face from a training set of images. Eigenfaces extends this approach by using principle component analysis (PCA) to reduce the dimensionality of images before matching. The following directory contains extensive skeleton code, as well as the training & testing images for the assignment
The main scriptfile, hw5_run.m, is written completely for you. You will only need to make modifications to print images for the writeup. There are 4 functions which you will need to code
This function implements the nearest-neighbor classification framework. It requires a set of "n" training points (X) and "n" training labels (Y). Given "m" test points with unknown labels, for each test point, it will return the label of the closest training point.function yguess = classifyNN(Xtest,X,Y) % yguess = classifyNN(Xtest,X,Y) % X: "d by n" design matrix % Y: "n by 1" vector of class labels % Xtest: "d by m" matrix of test points to classify % yguess: "m by 1" vector of output labels for test points
This function performs principle component analysis given the design matrix X. Each column of X is a vector representing a data point in high-dimensional space; in our case, the image of a face. Because d is quite large, it will be difficult to compute the eigenvectors of the entire covariance matrix, which will be "d by d". Rather, you should directly apply the SVD function on the centered design matrix [U,S,V] = svd(Xcen) , and only retain the "k" columns of U associated with the largest singular vectors.function [U,mu] = pca(X,k) % [U,mu] = pca(X,k) % X is a "d by n" matrix of n d-dimensional data points % 1) mu is a "d by 1" vector = average data point % 2) U is a "d by k" matrix of k column vectors spanning the low-dimensional space % in which the points live % 3) k is the number of principle component vectors to compute
This function projects the high-dimensional points from X into the k dimensional-space spanned by the vectors in U.function res = project_pca(X,U,mu) % res = project_pca(X,U,mu) % X: "d by n" matrix of n d-dimensional data points % U: "d by k" matrix of basis vectors % mu: "d by 1" vector of mean point % res: "k by n" matrix of points from X projected into space spanned by U
This function reconstructs a point x using k basis vectors from U.function res = reconstruct_pca(x,U,mu,k) % res = reconstruct_pca(x,U,mu,k) % x: "d by 1" vector % U: "d by k" matrix returned from pca % mu: "d by 1" vector returned from pca % k: the number of vectors used to reconstruct x % res: "d by 1" vector