function problem3(imageName, p)

% Obtain image data from file
[x,r,g,b,ni,nj] = loadImage(imageName);

% Converts image to shades of gray
xg = convertToGray(r,g,b);

% Produces Discrete Cosine Transorm Matrix
C = makeDCTMatrix(8);

% -------------------------
% 8x8 block
% -------------------------

% 8x8 block to experiment with
block = xg(1:8, 1:8);

% Compress and decompress 8x8 block
processBlock(block, C, 'linear');

% --------------------------
% Full Image
% --------------------------

% Generates linear quantization matrix
Q = createQuantizationMatrix(p, 'linear');

% Compresses image
compImage = compressImage(xg, ni, nj, C, Q);

% Decompress image
rebuiltImage = decompressImage(compImage, ni, nj, C, Q);
rebuiltImage = uint8(rebuiltImage);

% Displays full image
imagesc(rebuiltImage,[0 255]);
colormap(gray);