
% Load Alan
x=imread('Alan02','jpg');

% Crop Alan
startx=100;
starty=300;

N=256;
xg=double(x(startx:startx+N-1,starty:starty+N-1,2));
xg=xg-mean(mean(xg));

% Show Alan
imagesc(xg);
colormap gray
axis image

disp('Doing PCA .... !');
[u,s,v]=svd(xg,0);
eval=diag(s);

figure
plot(eval);
title('Singular value spectrum');

% Reconstruct 
comps=256;

figure
cyber_alan=zeros(N,N);
for i=1:comps,
    cyber_alan=cyber_alan+eval(i)*u(:,i)*v(:,i)';
    imagesc(cyber_alan);
    colormap gray
    axis image
    title(sprintf('With %d components',i));
    disp('Press a key ...');
    pause;
end

title(sprintf('I''m Cyber-Alan ! with %d components',comps));

