# A Discrete Cosine Transform Demo

The Discrete Cosine Transform (DCT) algorithm constitutes an integral component of contemporary image/video processing applications.

The formal definition of DCT is:

$$X_k = \sum\limits_{n=0}^{N-1}{x_n}\cos{\left[\dfrac{\pi}{N}\left(n+\dfrac12\right)k\right]}\quad k=0,\ldots,N-1.$$

In JPEG standard, DCT algorithm is used to transform images to a set of independent parts (to reduce the entropy), and only after that can the image be quantized to decrease the number of bits to represent the image.

Note that DCT is a lossless transformation, and only the quantization remove some less important data.

The following demo, which is written in Matlab, demonstrates that DCT is lossless, because data is transformed and then restored to original data.

The result is:

As you can see, gx=fx, therefore DCT is lossless.

If you want to learn DCT, this is best tutorial book: The Discrete Cosine Transform (DCT): Theory and Application