SHARE
TWEET

Untitled

a guest Nov 14th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. clear
  2. clc
  3. %% Uloha 1
  4. im = rgb2ycbcr(imread('lena_color_256.tif'));
  5. [height,width,channels] = size(im);
  6.  
  7. figure;
  8. imshow(ycbcr2rgb(im));
  9.  
  10. QL =    [16 11 10 16 24 40 51 61
  11. 12 12 14 19 26 58 60 55
  12. 14 13 16 24 40 57 69 56
  13. 14 17 22 29 51 87 80 62
  14. 18 22 37 56 68 109 103 77
  15. 24 35 55 64 81 104 113 92
  16. 49 64 78 87 103 121 120 101
  17. 72 92 95 98 112 100 103 99];
  18.  
  19. QC =    [17 18 24 47 99 99 99 99
  20. 18 21 26 66 99 99 99 99
  21. 24 26 56 99 99 99 99 99
  22. 47 66 99 99 99 99 99 99
  23. 99 99 99 99 99 99 99 99
  24. 99 99 99 99 99 99 99 99
  25. 99 99 99 99 99 99 99 99
  26. 99 99 99 99 99 99 99 99];
  27.  
  28. q = 50;
  29.  
  30. if q < 50
  31.     alfa = 50/q;
  32. else
  33.     alfa = 2 - (q/50);
  34. end
  35.  
  36. imc = zeros(height,width,channels);
  37.  
  38. for y = 1:8:height
  39.     for x = 1:8:width
  40.         Y = dct2(im(y:y+7,x:x+7,1));
  41.         Cb = dct2(im(y:y+7,x:x+7,2));
  42.         Cr = dct2(im(y:y+7,x:x+7,3));
  43.         Y = round(Y./(alfa*QL));
  44.         Cb = round(Cb./(alfa*QC));
  45.         Cr = round(Cr./(alfa*QC));
  46.        
  47.         Y = Y.*(QL/alfa);
  48.         Cb = Cb.*(QC/alfa);
  49.         Cr = Cr.*(QC/alfa);
  50.        
  51.         Y = idct2(Y);
  52.         Cb = idct2(Cb);
  53.         Cr = idct2(Cr);
  54.        
  55.         imc(y:y+7,x:x+7,1) = Y;
  56.         imc(y:y+7,x:x+7,2) = Cb;
  57.         imc(y:y+7,x:x+7,3) = Cr;
  58.     end
  59. end
  60.  
  61. % do zadania udat pocet nenulovych bodov po dct a po round ... aby sme
  62. % znazornili pomer kompresie
  63. imcc = uint8(imc);
  64. figure;
  65. imshow(ycbcr2rgb(imcc));
RAW Paste Data
Top