Documentation

This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

dctmtx

Discrete cosine transform matrix

Syntax

```D = dctmtx(n) ```

Description

`D = dctmtx(n)` returns the `n`-by-`n` DCT (discrete cosine transform) matrix. `D*A` is the DCT of the columns of `A` and `D'*A` is the inverse DCT of the columns of `A` (when `A` is `n`-by-`n`).

Class Support

`n` is an integer scalar of class `double`. `D` is returned as a matrix of class `double`.

Examples

collapse all

Read image into the workspace and cast it to class `double`.

`A = im2double(imread('rice.png'));`

Calculate discrete cosine transform matrix.

`D = dctmtx(size(A,1));`

Multiply the input image A by D to get the DCT of the columns of A and by D' to get the inverse DCT of the columsn of A.

```dct = D*A*D'; figure, imshow(dct)```

Tips

If `A` is square, the two-dimensional DCT of `A` can be computed as `D*A*D'`. This computation is sometimes faster than using `dct2`, especially if you are computing a large number of small DCTs, because `D` needs to be determined only once.

For example, in JPEG compression, the DCT of each 8-by-8 block is computed. To perform this computation, use `dctmtx` to determine `D`, and then calculate each DCT using `D*A*D'` (where `A` is each 8-by-8 block). This is faster than calling `dct2` for each individual block.