function gryimg(X, p) 
[m,n]=size(X);
imgc = zeros(m,n);
s = m/8;
t = n/8;
k = 8;
for i=2:k
    for j=1:k
        C(i,j)=sqrt(2/k)*cos((i-1)*(j-1/2)*pi/k);
    end
end
C(1,1:k)=ones(1,k)/sqrt(k);
for w=0:2
Q = p*8./hilb(8);
Xd = double(X);
for i=1:s
    for j=1:t
       X8 = Xd(((i-1)*8+1):(i*8),((j-1)*8+1):(j*8));
       Xc = X8 - 128;
       Y = C*Xc*C';
       Yq = round(Y./Q);
       Ydq = Yq.*Q;
       Xdq = C'*Ydq*C;
       Xe = Xdq+128;
       imgc(((i-1)*8+1):(i*8),((j-1)*8+1):(j*8)) = Xe;
    end
end
subplot(2,2,w+2)
imagesc(uint8(imgc));colormap(gray)
title(['compressed p =' int2str(2^w)])
end
subplot(2,2,1)
imagesc(uint8(X));colormap(gray)
title('original')



  