% Image compression for .jpg files. infile = 'jf2.jpg'; A= imread(infile,'jpg'); A= im2double(A); A=rgb2gray(A); subplot(2,2,1); imshow(A) [U,S,V] = svd(A); [m n] = size(S); Anew= zeros(m,n); Rank=6; for k=1:Rank Anew = Anew + S(k,k)*kron(U(:,k), V(:,k).'); end subplot(2,2,2) imshow(Anew) Anew= zeros(m,n); Rank=30; for k=1:Rank Anew = Anew + S(k,k)*kron(U(:,k), V(:,k).'); end subplot(2,2,3) imshow(Anew) Anew= zeros(m,n); Rank=60; for k=1:Rank Anew = Anew + S(k,k)*kron(U(:,k), V(:,k).'); end subplot(2,2,4) imshow(Anew)