x = imread('DH1.jpg'); 
% Original image is a multiple of 8 
x=double(x);
r=x(:,:,1); g=x(:,:,2); b=x(:,:,3);
xgray=0.2126*r+0.7152*g+0.0722*b;
figure(1);imagesc(uint8(xgray));colormap(gray)
Xd=xgray(81:88,91:98);
figure(2);imagesc(Xd);colormap(gray)

p=10;
Q=p*8./hilb(8);

Xc=Xd-128;
C=dct(eye(8));
Y=C*Xc*C';
Yq=round(Y./Q);

% To recover the image we use: 
Ydq=Yq.*Q;
Xdq=C'*Ydq*C;
Xe=Xdq+128;
figure(3);imagesc(uint8(Xe)); colormap(gray);
title(['Compressed p = 10' ]);

figure(4);imagesc(uint8(Xe), [0 255]); colormap(gray); 
% [0 255] so that it gives the right intensity of gray-ness, rather than relative intensity 
% figure(4);imagesc(Xf);colormap(gray) 
% %here you can compare one wihtout [0 255]

