Code covered by the BSD License  

Highlights from
image compression

image compression

by

 

image compression using svd

out=svdpix(p)
function out=svdpix(p) 
% SVDME(P). Supply image(=matrix) as obtained from
% p=imread('einstein.gif'). Selfdemonstarting provided
% the sample image file 'me.tif' exists in the path.
%
% Illustrates the use of singular value decompositions
% for image compression.
% This is a first trial version ... and as time permits
% it might be further elaborated.
%
% Matthias Kawski. http://math.la.asu.edu/~kawski
% Original: August 2000
%
if nargin < 1
   p=imread('einstein.gif');
elseif size(p,1) == 1   
   p=imread(p) ;
end
% q=p(15:55,11:50,:);
p=double(p);
% q=q(:,:,1)+q(:,:,2)+q(:,:,3);
p=63*p/max(max(p));
p=64-p;
qim=figure;
set(qim,'Position',[50 300 300 300]);
colormap(gray);
image(p)
[U,S,V] = svd(p);
N=min(size(S));
w=size(S,2);
qsvd=figure;
set(qsvd,'Position',[350 300 300 300]);
colormap(gray);
for k=[1:N-1]
   image(U*S*diag([ones(1,k),zeros(1,w-k)])*V')
   title(strcat('Number of singular values used: ',...
                 num2str(k)))
   pause
end
delete(qsvd)
delete(qim)

Contact us