The Discrete Cosine Transform is a linear transform, which maps an n-dimensional vector to set of n coefficients. A linear combination of n known basis vectors weighted with the n coefficients will result in the original vector. The known basis vectors of transforms from this class are “sinusoidal“, which means that they can be represented by sinus shaped waves or, in other words, they are strongly localized in the frequency spectrum. Therefore one speaks about transformation to the frequency domain. The most popular member of this class is the Discrete Fourier Transformation (DFT).The difference between DCT and DFT is that DFT applies to complex numbers, while DCT uses just real numbers. For real input data with even symmetry DCT and DFT are equivalent.
In JPEG compression the input data are two-dimenssional, presented in 8x8 blocks. There's a need of using two-dimenssional DCT. Since each dimension can be handled separately, the two-dimensional DCT follows straightforward form the one-dimensional DCT. A one-dimensional DCT is performed along the rows and then along the columns, or vice versa.
The formula used for one-dimensional DCT:
The formula used for two-dimensional DCT:
Applying these formulas directly requires much computational resources therefore an implementation in hardware can be very efficient.
The figure below, shows example of 8x8 block before DCT.
After Discrete Cosine Transform the block has following values:
As it can be seen higher values of transform coefficients are concentrated on the top left corner. In the frequency domain it looks like low frequency has advantage over high frequency. It is shown on the figure below.
As you can see only small amount of low frequency elements dominates over the rest of the coefficients. It allows to reduce data during next stages of JPEG compression.