clear
close all

% load image
im_orig = imread('Pics/parrot.jpg');

% encode
jpg = jpeg_encode(im_orig, 1, 1);

% decode
im_decoded = jpeg_decode(jpg);

% compute PSNR
diff2 = (im_decoded - im_orig).^2;
MSE = mean(diff2(:));
PSNR = 20*log10(255/sqrt(MSE));

% plot results
figure;
subplot(1,2,1);
imshow(im_orig);
subplot(1,2,2);
imshow(im_decoded);
title(sprintf('PSNR = %.0f dB', PSNR));
