function [k]=algo2(p)
x=imread('a3.jpg');
n=256;
% figure(1)
% imagesc(x);colormap(gray) %plots the color picture

x=double(x);
r=x(:,:,1);g=x(:,:,2);b=x(:,:,3);

[Ru Rs Rv]=svd(r);
[Gu Gs Gv]=svd(g);
[Bu Bs Bv]=svd(b);

Rrec=zeros(256,256,1);
Grec=zeros(256,256,1);
Brec=zeros(256,256,1);

k=round(n^2/(p*(2*n+1)));
for i=1:k
   Rrec=Rrec+Rs(i,i)*Ru(:,i)*Rv(:,i)'; 
   Grec=Grec+Gs(i,i)*Gu(:,i)*Gv(:,i)';
   Brec=Brec+Bs(i,i)*Bu(:,i)*Bv(:,i)';
end
Xrec(:,:,1)=uint8(Rrec);
Xrec(:,:,2)=uint8(Grec);
Xrec(:,:,3)=uint8(Brec);
figure(2)
imagesc(Xrec);colormap(gray)
