x = imread('project5original.jpg');
xd = double(x);
RED=xd(:,:,1);
GREEN=xd(:,:,2);
BLUE=xd(:,:,3);
picture1 = xd(160:167,74:81,1:3);
figure(1); imagesc(uint8(picture1),[0 255])
%p = 1;
%p = 2;
p = 4;
Q = p*8./hilb(8);

xbred = RED(160:167,74:81);
xbgreen = GREEN(160:167,74:81);
xbblue = BLUE(160:167,74:81);

%For Red
xcred = xbred - 128;
yred = dct(dct(xcred')');
yqred=round(yred./Q)
ydqred = yqred.*Q;
xdqred = idct(idct(ydqred')');
xered = xdqred + 128;

%For Green
xcgreen = xbgreen - 128;
ygreen = dct(dct(xcgreen')');
yqgreen=round(ygreen./Q)
ydqgreen = yqgreen.*Q;
xdqgreen = idct(idct(ydqgreen')');
xegreen = xdqgreen + 128;

%For Blue
xcblue = xbblue - 128;
yblue = dct(dct(xcblue')');
yqblue=round(yblue./Q)
ydqblue = yqblue.*Q;
xdqblue = idct(idct(ydqblue')');
xeblue = xdqblue + 128;

%Adds to compressed image
picture = zeros(8,8,3);
picture(1:8,1:8,1) = xered;
picture(1:8,1:8,2) = xegreen;
picture(1:8,1:8,3) = xeblue;

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