The discrete cosine transform (DCT) is an invertible linear mapping defined by:
, where , and
The unitary discrete cosine transform is given by multiplying the first row of by , and the rest of by .
The unitary DCT has the convenient property of preserving 2-norms. The DCT can be viewed as a change of basis from the standard basis to a cosine basis. The inverse of the DCT is given by :
, where ,
, and
Since the matrix is real, the DCT and IDCT are closed under . Using the DCT on real vectors is arguably the most common use-case. In this real case the unitary version is called an orthogonal discrete cosine transform.
The DCT is interesting for the same reasons as the discrete Fourier transform. However, especially when applied to natural images, the DCT has a strong energy compaction property, which means that most of the information (length) of a vector is contained in the first few coefficients. This property has been extensively taken advantage of in image compression.
Pastel implements efficient algorithms for computing the DCT and the IDCT, when is a power of two. Both the standard and the orthogonal version are provided, as well as both real and complex versions.
Pastel also provides the in-place versions of the DCT as range algorithms, so that applying them to arrays is easy.