基于dct变换的图像编解码(包含Z扫描与反Z扫描)的matlab程序

function dct_code
orgbgr = imread('lena.jpg');
orggray = rgb2gray(orgbgr);
figure('color','white'),imshow(orggray),title('原始图像');
org = im2double(orggray);
D   = dctmtx(8);               //DCT变换矩阵
[m n] = size(orggray);
%使用的量化表
standard = [
1 1 1 1 0 0 0 0;
1 1 1 0 0 0 0 0;
1 1 0 0 0 0 0 0;
1 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
];
%z 编排所用数组
z = [0  1  8 16  9  2  3 10 
    17 24 32 25 18 11  4  5
    12 19 26 33 40 48 41 34
    27 20 13  6  7 14 21 28
    35 42 49 56 57 50 43 36 
    29 22 15 23 30 37 44 51
    58 59 52 45 38 31 39 46
    53 60 61 54 47 55 62 63];
z=z';z=z(:);
%% 编码程序
fdctdata = zeros(m,n);
for row = 1 : m/8
    for col = 1 : n/8
        src_tem = org((row-1)*8+1:(row-1)*8+8,(col-1)*8+1:(col-1)*8+8);
        fdctdata((row-1)*8+1:(row-1)*8+8,(col-1)*8+1:(col-1)*8+8) = D * src_tem * D';
    end
end
%量化DCT系数
for row = 1 : m/8
    for col = 1 : n/8
        for i=1:8
            for j=1:8
      

你可能感兴趣的:(编解码)