Singular vector decomposition and low rank approximation application for image compression

Created Diff never expires
21 removals
37 lines
7 additions
23 lines
function C=compressimage(k)
function C=compressimage2(k)


A=imread('/home/phung/Pictures/einstein.jpg');
A=imread('/home/phung/Pictures/einstein.jpg');


B=A(:,:,1);
B=A(:,:,1);


B=im2double(B);
B=im2double(B);


% imshow(B);
% imshow(B);


[U,S,V]=svd(B);
sigma = B' * B;

[m,n]=size(S);

n=min(m,n);

% plot([1:n,diag(S),'.');

% axis([-10,n+1,0,300]);

% hold on

C=diag(S)';


for i=k+1:n
[U,S,V]=svd(sigma);


S(i,i)=0;
UR = U(:,1:k);

end


B=U*S*V';
Breduced = B *UR;


imshow(B);
Breconstructed = Breduced * UR' ;


C=C';
imshow(Breconstructed);


end
end