function Project5b(p)

x = imread('cheetah.jpg');
xd = double(x);
r = xd(:,:,1);g = xd(:,:,2);b = xd(:,:,3);

% Original 496 x 496 image
figure(1); imagesc(x); axis square;

Q = p*8./hilb(8);
C = getC();
Xf = zeros(496,496,3);

for i= 1:8:496
    for j = 1:8:496
                % Quantizize
        % Red
        R = r(i:i+7,j:j+7);
        R1 = R - 128;
        Yr = dct(dct (R1')');
        Yqr = round(Yr./Q);
        % Green
        G = g(i:i+7,j:j+7);
        G1 = G - 128;
        Yg = dct(dct (G1')');
        Yqg = round(Yg./Q);
        % Blue
        B = b(i:i+7,j:j+7);
        B1 = B - 128;
        Yb = dct(dct (B1')');
        Yqb = round(Yb./Q);
               
                % Dequantizize
        % Red
        Ydqr = Yqr.*Q;
        Xdqr = C'*Ydqr*C;
        Xer = Xdqr + 128;
        Xf(i:i+7,j:j+7,1) = Xer; 
        % Green 
        Ydqg = Yqg.*Q;
        Xdqg = C'*Ydqg*C;
        Xeg = Xdqg + 128;
        Xf(i:i+7,j:j+7,2) = Xeg;
        % Blue
        Ydqb = Yqb.*Q;   
        Xdqb = C'*Ydqb*C;
        Xeb = Xdqb + 128;        
        Xf(i:i+7,j:j+7,3) = Xeb;
        
    end
end
figure(2);imagesc(uint8(Xf)); 
axis square;
