Image Processing Toolbox User's Guide |
Compute two-dimensional discrete cosine transform
Syntax
Description
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(k1,k2).
B = dct2(A,m,n)
or 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
.
Class Support
A
can be numeric or logical. The returned matrix B
is of class double
.
Algorithm
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
where 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
.
Example
The commands below compute the discrete cosine transform for the autumn
image. Notice that most of the energy is in the upper left corner.
RGB = imread('autumn.tif'); I = rgb2gray(RGB); J = dct2(I); imshow(log(abs(J)),[]), colormap(jet(64)), colorbar
Now set values less than magnitude 10 in the DCT matrix to zero, and then reconstruct the image using the inverse DCT function idct2
.
See Also
References
[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.
cpstruct2pairs | dctmtx |
© 1994-2005 The MathWorks, Inc.