dct8.m

来自「It will take a DCT of Jpg image.」· M 代码 · 共 47 行

M
47
字号
%%%% Dct for 8*8 Array
function out_put=DCT8(A)
A=double(A);
out_put=zeros(size(A));


N=8;   %Number of Rows
M=8;   %Number of Columns
X=N*M;
x=1;    %For point zero
for q=(1-x):N-1                 % 8 times
      for p=(1-x):M-1           % 8 times
       if (p==0)   
           u=1/sqrt(M);          %value of u for p=0
       else 
           u=sqrt(2/M);          %value of u for p other than 0
       end

       if (q==0)                
           v=1/sqrt(N);          %value of v for q=0
       else  
           v=sqrt(2/N);          %value of v for q other than 0
       end

        %%%% Constants %%%%
      for m=1:M                 % 8 times
        for n=1:N               % 8 times
       t(n,m) = cos(((2*(n-1)+1)*pi*p)/(2*N))*cos(((2*(m-1)+1)*pi*q)/(2*M)); %matrix of 8*8
        end
      end

      
coef1=A.*t;
coeff_sum=0;

%%%%ADDING COEFFICENT%%%%
for y=1:X
coeff_sum=[coef1(y)+coeff_sum];
end
%%%%FINAL DCT%%%%%
final_dct=u*v*coeff_sum;

out_put(p+1,q+1)=final_dct;
      end
  end
 
 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?