%% Sample script for the "author" data % Some cleaning commands: close all; %Close all open figures clear %Clear the memory clc %Clear the command window % Download the data from the class website, so it can be loaded here: load FacesNoRem Y1=double(Y); %Changes the data from "integers" to "floating point" %The data was saved as integers to save on memory. % We can visualize the first 4 faces: figure(1) for j=1:4 temp=reshape(Y1(:,j),294,262); imagesc(temp); colormap(gray); axis equal; axis off; end %% Find the mean of the collection, subtract it (different label to save the original data) Ymean=mean(Y1,2); figure(2) % Plot the mean face: X=Y1-repmat(Ymean,1,109); %% The SVD [U,S,V]=svd(X,'econ'); tempS=diag(S).^2; tempS=tempS/sum(tempS); %Normalized eigenvalues. figure(3) % Plot the normalized eigenvalues %% Visualize the basis vectors- Here are 4 of them figure(4) % Plot the first four eigenvectors as images %% Projection to R^2 Coord=U(:,1:2)'*X; %The matrix Xcoords is now 2 x 109 figure(5) % Plot the two dimensional coordinates: %% Visualize the reconstructed faces: Recon=U(:,1:2)*Coord; % Plot some of the reconstructed faces: