Main Content

dctmtx

Discrete cosine transform matrix

Description

example

D= dctmtx(n)returns then-by-ndiscrete cosine transform (DCT) matrix, which you can use to perform a 2-D DCT on an image.

Examples

collapse all

Read an image into the workspace and cast it to classdouble.

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

Figure contains an axes object. The axes object contains an object of type image.

Calculate the discrete cosine transform matrix.

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

Multiply the input imageAbyDto get the DCT of the columns ofA, and byD'to get the inverse DCT of the columns ofA.

dct = D*A*D'; imshow(dct)

Figure contains an axes object. The axes object contains an object of type image.

Input Arguments

collapse all

Size of DCT matrix, specified as a positive integer.

Data Types:double

Output Arguments

collapse all

DCT matrix, returned as a numeric matrix of sizen-by-n.

Data Types:double

Tips

  • If you have ann-by-nimage,A, thenD*Ais the DCT of the columns ofAandD'*Ais the inverse DCT of the columns ofA.

  • The two-dimensional DCT ofAcan be computed asD*A*D'. This computation is sometimes faster than usingdct2, especially if you are computing a large number of small DCTs, becauseDneeds to be determined only once.

    For example, in JPEG compression, the DCT of each 8-by-8 block is computed. To perform this computation, usedctmtxto determineD, and then calculate each DCT usingD*A*D'(whereAis each 8-by-8 block). This is faster than callingdct2for each individual block.

已经rsion History

Introduced before R2006a

See Also