Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [] = jpeg_codec()
- A = imread('C:\Users\lab\Desktop\exercise_5\Lena_gray_8.tif');
- B = double(A);
- B = B-128;
- %quantization
- Bdct = blkproc(B, [8, 8], 'dct2');
- Bquant = blkproc(Bdct, [8, 8], 'quantization');
- zeros = nnz(Bquant);
- %dequantization
- Bdequant = blkproc(Bquant, [8, 8], 'dequantization');
- Bidct = blkproc(Bdequant, [8, 8], 'idct2');
- Bres = Bidct + 128;
- Bres = Bres/255;
- Bres = im2uint8(Bres);
- subplot(1,2,1);
- imshow(A);
- title('original');
- subplot(1,2,2);
- imshow(Bres);
- title('reconstructed');
- perc = zeros / (size(Bquant, 1)*size(Bquant, 2)) * 100;
- fprintf('percentage of zeros in the array is: %f %%', perc);
- [mse psnr] = mse_error(A, Bres);
- x = [1:1:10];
- mse = [33.0081, 56.1949, 75.0029, 92.5555, 110.2101, 128.9915, 147.4825, 164.9354, 184.2403, 200.5774];
- psnr = [32.9446, 30.6338, 29.3800, 28.4668, 27.7086, 27.0252, 26.4434, 25.9577, 25.4770, 25.1080];
- figure
- plot(x, mse, x, psnr);
- xlabel('alpha value');
- ylabel('msn, psnr errors');
- end
Add Comment
Please, Sign In to add comment