x = imread('project5original.jpg');
xd = double(x);
r=xd(:,:,1);
g=xd(:,:,2);
b=xd(:,:,3);
Xgray =0.2126*r+0.7152*g+0.0722*b;
xgray = uint8(Xgray);
figure(1); imagesc(xgray); colormap(gray);
[m,n,a] = size(x);
%p = 1;
%p = 2;
%p = 4;
p = 100;
Q = p*8./hilb(8);
picture = zeros(m,n);
for i = 1:8:m
    for j =1:8:n 
        partialxgray =Xgray(i:i+7,j:j+7);
        xb = double(partialxgray);
        xc = xb - 128;
        y = dct(dct(xc')');
        xd = double(xc);
        yq=round(y./Q);
        yq1 = double(yq);
        ydq = yq1.*Q;
        xdq = idct(idct(ydq')');
        xe = xdq + 128;
        picture(i:i+7,j:j+7) = xe;
    end

end
figure(2);imagesc(uint8(picture), [0,255]); colormap(gray)
