Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear
- clc
- %% Uloha 1
- im = rgb2ycbcr(imread('lena_color_256.tif'));
- [height,width,channels] = size(im);
- figure;
- imshow(ycbcr2rgb(im));
- QL = [16 11 10 16 24 40 51 61
- 12 12 14 19 26 58 60 55
- 14 13 16 24 40 57 69 56
- 14 17 22 29 51 87 80 62
- 18 22 37 56 68 109 103 77
- 24 35 55 64 81 104 113 92
- 49 64 78 87 103 121 120 101
- 72 92 95 98 112 100 103 99];
- QC = [17 18 24 47 99 99 99 99
- 18 21 26 66 99 99 99 99
- 24 26 56 99 99 99 99 99
- 47 66 99 99 99 99 99 99
- 99 99 99 99 99 99 99 99
- 99 99 99 99 99 99 99 99
- 99 99 99 99 99 99 99 99
- 99 99 99 99 99 99 99 99];
- q = 50;
- if q < 50
- alfa = 50/q;
- else
- alfa = 2 - (q/50);
- end
- imc = zeros(height,width,channels);
- for y = 1:8:height
- for x = 1:8:width
- Y = dct2(im(y:y+7,x:x+7,1));
- Cb = dct2(im(y:y+7,x:x+7,2));
- Cr = dct2(im(y:y+7,x:x+7,3));
- Y = round(Y./(alfa*QL));
- Cb = round(Cb./(alfa*QC));
- Cr = round(Cr./(alfa*QC));
- Y = Y.*(QL/alfa);
- Cb = Cb.*(QC/alfa);
- Cr = Cr.*(QC/alfa);
- Y = idct2(Y);
- Cb = idct2(Cb);
- Cr = idct2(Cr);
- imc(y:y+7,x:x+7,1) = Y;
- imc(y:y+7,x:x+7,2) = Cb;
- imc(y:y+7,x:x+7,3) = Cr;
- end
- end
- % do zadania udat pocet nenulovych bodov po dct a po round ... aby sme
- % znazornili pomer kompresie
- imcc = uint8(imc);
- figure;
- imshow(ycbcr2rgb(imcc));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement