xcol=imread('colorimg.jpg')
xdco=double(xcol);
r=xdco(:,:,1);g=xdco(:,:,2); b=xdco(:,:,3);
y = 0.299*r + 0.587*g + 0.114*b;
u = b - y;
v = r - y;

n=8;
for i=2:n
   for j=1:n
       K(i,j)=sqrt(2/n)*cos((i-1)*(j-1/2)*pi/n);
   end
end
K(1,1:n)=ones(1,n)/sqrt(n);
p=1;
Q =p* [16 11 10 16 24 40 51 61;
     12 12 14 19 26 58 60 55;
     14 13 16 24 40 57 69 56;
     14 17 22 29 51 87 80 62;
     18 22 37 56 68 109 103 77;
     24 35 55 64 81 104 113 92;
     49 64 78 87 103 121 120 101;
     72 92 95 98 112 100 103 99;];
 
Qc = [17 18 24 47 99 99 99 99; 
      18 21 26 66 99 99 99 99;
      24 26 56 99 99 99 99 99;
      47 66 99 99 99 99 99 99;
      99 99 99 99 99 99 99 99;
      99 99 99 99 99 99 99 99;
      99 99 99 99 99 99 99 99;
      99 99 99 99 99 99 99 99];
  
Xf = zeros(192,192)
Y = y(81:88,81:88);
Y1 = Y - 96;
Yy = K*Y1*K';
Yqy = round(Yy./Q);

U = u(81:88,81:88);
U1 = U - 96;
Yu = K*U1*K';
Yqu = round(Yu./Qc);

V = v(81:88,81:88);
V1 = V - 96;
Yv = K*V1*K';
Yqv = round(Yv./Qc);

Ydqy = Yqy.*Q;
Xdqy = K'*Ydqy*K;
Xey = Xdqy + 96;


Ydqu = Yqu.*Qc;
Xdqu = K'*Ydqu*K;
Xeu = Xdqu + 96;


Ydqv = Yqv.*Qc;   
Xdqv = K'*Ydqv*K;
Xev = Xdqv + 96;      


Xeb = Xeu + Xey;    
Xer = Xev + Xey;
Xeg = (Xey - 0.299*Xer - 0.114*Xeb)/(.587);

figure(1);
imagesc(Xey)

figure(2);
imagesc(Xeu)

figure(3)
imagesc(Xev)
