Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

2-D discrete cosine transform

`B = dct2(A)`

B = dct2(A,m,n)

B = dct2(A,[m n])

`B = dct2(A)`

returns the two-dimensional
discrete cosine transform of `A`

. The matrix `B`

is
the same size as `A`

and contains the discrete cosine
transform coefficients *B(k*_{1}*,k*_{2}*).*

`B = dct2(A,m,n)`

pads the
matrix `A`

with 0's to size `m`

-by-`n`

before
transforming. If `m`

or `n`

is smaller
than the corresponding dimension of `A`

, `dct2`

truncates `A`

.

`B = dct2(A,[m n])`

same as
above.

`A`

can be numeric or logical. The returned
matrix `B`

is of class `double`

.

The discrete cosine transform (DCT) is closely related to the
discrete Fourier transform. It is a separable linear transformation;
that is, the two-dimensional transform is equivalent to a one-dimensional
DCT performed along a single dimension followed by a one-dimensional
DCT in the other dimension. The definition of the two-dimensional
DCT for an input image `A`

and output image `B`

is

$${B}_{pq}={\alpha}_{p}{\alpha}_{q}{\displaystyle \sum _{m=0}^{M-1}{\displaystyle \sum _{n=0}^{N-1}{A}_{mn}\mathrm{cos}\frac{\pi (2m+1)p}{2M}}}\mathrm{cos}\frac{\pi (2n+1)q}{2N},\text{}\begin{array}{c}0\le p\le M-1\\ 0\le q\le N-1\end{array}$$

where

$${\alpha}_{p}=\{\begin{array}{c}\frac{1}{\sqrt{M}},\text{}p=0\text{}\\ \sqrt{\frac{2}{M}},\text{}1\le p\le M-1\end{array}$$

and

$${\alpha}_{q}=\{\begin{array}{c}\frac{1}{\sqrt{N}},\text{}q=0\text{}\\ \sqrt{\frac{2}{N}},\text{1}\le \text{q}\le \text{N-1}\end{array}$$

*M* and *N* are the row
and column size of `A`

, respectively. If you apply
the DCT to real data, the result is also real. The DCT tends to concentrate
information, making it useful for image compression applications.

This transform can be inverted using `idct2`

.

[1] Jain, Anil K., *Fundamentals
of Digital Image Processing,* Englewood Cliffs, NJ, Prentice
Hall, 1989, pp. 150-153.

[2] Pennebaker, William B., and Joan L. Mitchell, *JPEG:
Still Image Data Compression Standard,* Van Nostrand Reinhold,
1993.

Was this topic helpful?