clear

function imCompressed = compress(imFullOneChannel, SingularValuesToKeep)
    [U, Sigma, V] = svd(imFullOneChannel);
    SingularValues = diag(Sigma)
    imCompressed = U(:, 1:SingularValuesToKeep)*diag(SingularValues(1:SingularValuesToKeep))*V(:, 1:SingularValuesToKeep)'
endfunction

im = imread('lena.png');
imshow(im)

imFull = double(im);

imCompressed(:, :, 1) = compress(imFull(:, :, 1), 50);
imCompressed(:, :, 2) = compress(imFull(:, :, 2), 50);
imCompressed(:, :, 3) = compress(imFull(:, :, 3), 50);

imCompressedFinal = uint8(imCompressed);
imshow(imCompressedFinal)