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;
imagesc(uint8(Xgray)); colormap(gray);

xb = Xgray(160:167,74:81);
figure(1);imagesc(uint8(xb), [0,255])

%Part B
xb1 = double(xb);
xc = xb1 - 128;
y = dct(dct(xc')');

%Part C
p = 1;
%p = 2;
%p = 4;
qy = p.*[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];
yq=round(y./qy)

  
%Part D
yq1 = double(yq);
ydq = yq1.*qy;
xdq = idct(idct(ydq')');
xe = xdq + 128;
figure(2);imagesc(uint8(xe), [0,255]);colormap(gray);