% Script for 11.2 computer problem 3
% relevant picture files:
%   p3base.png
%   p3quant1.png
%   p3quant2.png
%   p3quant4.png

image = imread('codyPic.jpg');
imgray = rgbim2gray(image);

im8x8 = imgray(96:(96+7),1:8);
C=dctMat(8);
Q=8./hilb(8);
figure;imagesc(im8x8);colormap(gray); % p3base.png

im8x8dct=twoDimDCT(im8x8,C);
im8x8q1=round(im8x8dct./Q);
im8x8q1

im8x8r1 = invertTwoDimDCT(im8x8q1.*Q,C);
im8x8ru1=uint8(im8x8r1);
figure;colormap(gray);imagesc(im8x8ru1); % p3quant1.png
Q=Q.*2;
im8x8q2=round(im8x8dct./Q);
im8x8q2

im8x8r2 = invertTwoDimDCT(im8x8q2.*Q,C);
im8x8ru2=uint8(im8x8r2);
figure;colormap(gray);imagesc(im8x8ru2); % p3quant2.png

Q=Q.*2;
im8x8q4=round(im8x8dct./Q);
im8x8q4

im8x8r4 = invertTwoDimDCT(im8x8q4.*Q,C);
im8x8ru4=uint8(im8x8r4);
figure;colormap(gray);imagesc(im8x8ru4); % p3quant4.png