function pcargbtawny2

%Get data
Y = imread('tawny.bmp','bmp');
[m,n,o]=size(Y)
image(Y)
%colormap(gray(256))
axis image, axis off

class(Y)

%Convert matrix to double so that we can use the command svd
%we'll have to re-convert to uint8 later to use image properly.
X=double(Y);

% %Now, let's look at a logarithmic plot of the singular values
Xr=X(:,:,1);
Xg=X(:,:,2);
Xb=X(:,:,3);
[Ur,Sr,Vr] = svd(Xr);
sigmar=diag(Sr);
figure
semilogy(sigmar,'.')
[Ug,Sg,Vg] = svd(Xg);
sigmag=diag(Sg);
figure
semilogy(sigmag,'.')
[Ub,Sb,Vb] = svd(Xb);
sigmab=diag(Sb);
figure
semilogy(sigmab,'.')

%Finally, let's compress the image, keeping only k singular values.
k=25;
AppXr=zeros(m,n);
AppXg=zeros(m,n);
AppXb=zeros(m,n);
 for i=1:k
     AppXr=AppXr+sigmar(i)*Ur(:,i)*Vr(:,i)';     
     AppXg=AppXg+sigmag(i)*Ug(:,i)*Vg(:,i)';     
     AppXb=AppXb+sigmab(i)*Ub(:,i)*Vb(:,i)';     
 end
AppX(:,:,1)=AppXr;
AppX(:,:,2)=AppXg;
AppX(:,:,3)=AppXb;


AppX=uint8(AppX);
figure
image(AppX)
axis image, axis off

end