close all

img = rgb2gray(imread('bob2.jpg'));
img = im2double(img);

figure()
imshow(img);
title('original image')

[U,S,V] = svd(img, 'econ');
VT = V';

for i=1:5:41 
    disp(i)
    pause(2) % my matlab dont like to plot images fast like this
    rank_k_img = U(:,1:i)*S(1:i,1:i)*VT(1:i,:);
    figure()
    imshow(rank_k_img);
    str = strcat('rank', num2str(i), 'approximation');
    title(str);

end

figure(100)
plot(diag(S))

% https://www.youtube.com/watch?v=I6cmIKIdROU