Guest User

Untitled

a guest
Apr 17th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function [] = jpeg_codec()
  2.     A = imread('C:\Users\lab\Desktop\exercise_5\Lena_gray_8.tif');
  3.     B = double(A);
  4.    
  5.     B = B-128;
  6.    
  7.     %quantization
  8.     Bdct = blkproc(B, [8, 8], 'dct2');
  9.     Bquant = blkproc(Bdct, [8, 8], 'quantization');
  10.     zeros = nnz(Bquant);
  11.    
  12.     %dequantization
  13.     Bdequant = blkproc(Bquant, [8, 8], 'dequantization');
  14.     Bidct = blkproc(Bdequant, [8, 8], 'idct2');
  15.    
  16.     Bres = Bidct + 128;
  17.     Bres = Bres/255;
  18.    
  19.     Bres = im2uint8(Bres);
  20.    
  21.     subplot(1,2,1);
  22.     imshow(A);
  23.     title('original');
  24.    
  25.     subplot(1,2,2);
  26.     imshow(Bres);
  27.     title('reconstructed');
  28.    
  29.     perc = zeros / (size(Bquant, 1)*size(Bquant, 2)) * 100;
  30.     fprintf('percentage of zeros in the array is: %f %%', perc);
  31.    
  32.     [mse psnr] = mse_error(A, Bres);
  33.    
  34.         x = [1:1:10];
  35.  
  36.     mse = [33.0081, 56.1949, 75.0029, 92.5555, 110.2101, 128.9915, 147.4825, 164.9354, 184.2403, 200.5774];
  37.  
  38.     psnr = [32.9446, 30.6338, 29.3800, 28.4668, 27.7086, 27.0252, 26.4434, 25.9577, 25.4770, 25.1080];
  39.    
  40.     figure
  41.     plot(x, mse, x, psnr);
  42.     xlabel('alpha value');
  43.     ylabel('msn, psnr errors');
  44. end
Add Comment
Please, Sign In to add comment