function [ X ] = DCT( A )
%DCT Generate the discrete cosine transform of the 2D input matrix.
    [N1 N2] = size(A);
    n1 = (1:N1) - 0.5;
    n2 = (1:N2) - 0.5;
    m1 = (1:N1)-1;
    m2 = (1:N2)-1;    
    T1 = sqrt(2/N1) * cos(m1' * n1 * pi / N1);
    T1(1,:) = T1(1,:) / sqrt(2);
    T2 = sqrt(2/N2) * cos(n2' * m2 * pi / N2);
    T2(:,1) = T2(:,1) / sqrt(2); 
    X = T1 * A * T2;
end