% h6dct2.m
%-------------------------------------------------------------------------
N=512;
Q=xlsread('Qtable.xls','A2:H9');
fin=fopen('peppers.raw','r');
I=fread(fin,[N,N],'uint8'); f=(I-128)';
C=zeros(N,N);
for i=1:8:N
    for j=1:8:N
        F=dct2(f(i:i+7,j:j+7));
        C(i:i+7,j:j+7)=F./Q;
    end
end
for i=1:N
    for j=1:N
        r=C(i,j);
        if (r>=0)
            C(i,j)=fix(0.5+C(i,j));
        else
            C(i,j)=fix(-0.5+C(i,j));
        end
    end
end
C(9:16,289:296),
C(249:256,121:128)