5;

[N,D]=size(X);
mean_face = mean(X);
%X = X - repmat(mean_face,N,1);
fprintf('Performing PCA.... stay tuned\n');
K = 100; 
[B, mu, Xp, Xrecon] = pcaPmtk(X, K);
%tic; [B] = pcaPmtk(X,K); toc
Xproj = X*B;

% visualize basis functions (eigenfaces)
figure;
subplot(2,2,1)
f = reshape(mean_face, [h w]);
imagesc(f);
axis off
for i=1:3
  subplot(2,2,i+1)
  f = reshape(B(:,i), [h w]);
  imagesc(f);
  axis off
end
colormap gray

% visualize reconstruction
figure;
subplot(2,2,1)
%imagesc(reshape(X(Selected_Face,:)+