function Project5a(p)

x = imread('cheetah.jpg');
x = double(x);
r = x(:,:,1);g = x(:,:,2);b = x(:,:,3);
Xgray = 0.2126*r + 0.7152*g + 0.0722*b;

% Original 496 x 496 image in gray scaele
figure(1); imagesc(Xgray); 
colormap(gray);
axis square;

Q = p*8./hilb(8);
%Q = [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;];
%Q = p*Q;
C = getC();
Xf = zeros(496,496);

for i= 1:8:496
    for j = 1:8:496
       
        % Quantizize
        X = Xgray(i:i+7,j:j+7);
        Xd = double(X);
        Xc = Xd - 128;
        Y = dct(dct(Xc')');
        Yq = round(Y./Q);

        % Dequantizize
        Ydq = Yq.*Q;
        Xdq = C'*Ydq*C;
        Xe = Xdq + 128;
        Xf(i:i+7, j:j+7) = uint8(Xe);
        
    end
end

figure(2);imagesc(uint8(Xf), [0,255]); 
colormap(gray)
axis square;


