%a = dir('*.jpg')
%
cwd = pwd;
cd('~/Teaching/MA211/Class2012');
a = dir('*.jpg')
%
%k = 500;
%for i = 1:length(a);
%	A{i} = imresize(imread(a(i).name),[k,k]);
%	M(:,i) = reshape(A{i}(:,:,1),k*k,1);
%end
%
%[u,s,v] = svd(double(M),0);
%
%
%for i = 1:size(u,2);
%		B{i} = (reshape(u(:,i),k,k));
%		AA = double(A{i});
%		C{i} = (AA(:,:,1)'*double(B{i}));
%end
%
%
%		
%cd(cwd);
%

clear F
[U,S,V] = svd(double(A{5}(:,:,1)));
f = 0*U(:,1)*V(i,:);
I = 500;
for i = 2:I
F{i} = U(:,i)*S(i,i)*V(:,i)';
end

G = 0*U(:,1)*V(1,:);
for i = 2:I
G = F{i} + G;
end

imagesc(G)
cd(cwd)
