function problem4(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
% -------------------------

% Original block
block = xg(1:8, 1:8);

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

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

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

% 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);