function gry8(X, p) 
[m,n]=size(X);n=m;
for i=2:n
    for j=1:n
        C(i,j)=sqrt(2/n)*cos((i-1)*(j-1/2)*pi/n);
    end
end
C(1,1:n)=ones(1,n)/sqrt(n);


for w=0:2
    %Q = 2^(w)*8./hilb(8);
    Q = (2^w)*[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];
    Xd = double(X);
    Xc = Xd - 128;
    Y = C*Xc*C';
    Yq = round(Y./Q);
    Ydq = Yq.*Q;
    Xdq = C'*Ydq*C;
    Xe = Xdq+128;
    subplot(2,2,w+2)
    imagesc(uint8(Xe));colormap(gray)
    title(['Compressed p = ' int2str(2^w)])
end
subplot(2,2,1)
imagesc(uint8(X));colormap(gray)
title('Original')


  