function svdPictures(fileName,fmt)
% Function svdPictures takes characters string that is either a filename or
% path of a picture file, and format the format the picture was saved in.
% Look imread documentation for more details. 
% Function shows the effects of svd packaging on picture. Please note that
% 3-d svd is done, and it might take awhile. 
close all; 
L = imread(fileName,fmt);
% show the initial image
imshow(L);
figure;
% strip the color layers (RGB assumed)
L1 = im2double(L(:,:,1));
L2 = im2double(L(:,:,2));
L3 = im2double(L(:,:,3));
disp('Layers, stripped');

[m,n] = size(L1);
% take the dimensions of picture
% do the svd. Note : depending on stuff, this can ostensibly take a VERY
% long time. Use common sense when selecting pictures.
[u1 s1 v1] = svd(L1);
[u2 s2 v2] = svd(L2);
[u3 s3 v3] = svd(L3);
% How many 
step = input('please provide step size');
disp('Factorisation, done');
boundary = min(m,n);
for k = 1:step:boundary
   % do the reconstruction by layer
   C1 = u1(:,1:k)*s1(1:k,1:k)*v1(:,1:k)';
   C2 = u2(:,1:k)*s2(1:k,1:k)*v2(:,1:k)';
   C3 = u3(:,1:k)*s3(1:k,1:k)*v3(:,1:k)';
   disp('Inner loop, done');
   fprintf('%d values included in picture out of %d\n',k,m);    
   % Collect the layers into a mxnx3 matrix Q. Also, 8-bit integers are
   % required, so do conversion, and hope no relevant data is lost. 
   Q(:,:,1) = im2uint8(C1);
   Q(:,:,2) = im2uint8(C2);
   Q(:,:,3) = im2uint8(C3);
   % show image. 
   imshow(Q);
   pause;
end
