2-D DCT
Compute 2-D discrete cosine transform (DCT)
Libraries:
Computer Vision Toolbox /
Transforms
Description
The 2-D DCT block calculates the two-dimensional discrete cosine transform of an image. Suppose f(x,y) is the input image of dimension M-by-N, the equation for the 2-D DCT is
where for and otherwise.
The number of rows and columns of the input image must be power of 2. You can also use this block to compute 1-D DCT of a vector.
Examples
Compress Image Using 2-D DCT
Compress an image using a 2-D discrete cosine transform (DCT). The example computes the 2-D DCT of 8-by-8 nonoverlapping blocks of the input image, discards (sets to zero) all but 10 of the 64 DCT coefficients in each block, and then reconstructs the image using the 2-D inverse discrete cosine transform (IDCT) of each block.
Ports
Input
Port_1 — Input data
matrix | vector
Input data, specified as a numeric matrix or a vector. The size of the input data must be power of 2.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
Output
Port_1 — Output data
matrix | vector
Output data containing the DCT coefficients, returned as a matrix or vector. The size and the datatype of the output is same as that of the input.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
Parameters
Main Tab
Sine and cosine computation — Specify how the block computes the sine and cosine terms
Table lookup
(default) | Trigonometric fcn
Use this parameter to specify how the block computes the sine and cosine terms in the DCT algorithm.
If you select
Trigonometric fcn
, the block computes the sine and cosine values during the simulation.If you select
Table lookup
, the block computes and stores the trigonometric values before the simulation starts. In this case, the block requires extra memory.Table lookup
is the default.
Data Types Tab
Fixed-point operational parametersRounding mode — Rounding mode for fixed-point representation
Floor
(default) | Ceiling
| Convergent
| Nearest
| Round
| Simplest
| Zero
Use this parameter to specify the rounding mode for the block to use when the specified data type and scaling cannot exactly represent the result of a fixed-point calculation. See Rounding Modes for more information on the available values.
Note
The sine table values do not obey this parameter; they always round to
Nearest
.
Saturate on integer overflow — Specify overflow mode
off (default) | on
When you select this parameter, the block saturates the result of its fixed-point operation. When you clear this parameter, the block wraps the result of its fixed-point operation.
For details on saturate and wrap, see Overflow Handling for fixed-point operations.
Note
The sine table values do not obey this parameter; instead, they are always saturated.
Sine Table — Data type of sine table
Inherit: Same word length as
input
(default) | fixdt(1,16)
| <data type expression>
Use this parameter to specify the word length of the values of the sine table. The fraction length of the sine table values always equals the word length minus one.
The sine table values do not obey the Rounding mode and
Saturate on integer overflow parameters; instead, they are always
saturated and rounded to Nearest
.
Product output — Data type of product output
Inherit: Inherit via internal
rule
(default) | Inherit: Same as input
| fixdt(1,16,0)
| <data type expression>
Use this parameter to specify the product output data type. See Fixed-Point Data Types and Multiplication Data Types for illustrations depicting the use of the product output data type in this block.
Accumulator — Data type of accumulator
Inherit: Inherit via internal
rule
(default) | Inherit: Same as input
| Inherit: Same as product output
| fixdt(1,16,0)
| <data type expression>
Use this parameter to specify the accumulator data type. See Fixed-Point Data Types for illustrations depicting the use of the accumulator data type in this block.
Output — Data type of output
Inherit: Inherit via internal
rule
(default) | Inherit: Same as input
| fixdt(1,16,0)
| <data type expression>
Use this parameter to specify the output data type. See Fixed-Point Data Types for illustrations depicting the use of the output data type in this block. When you set this parameter to
Inherit: Inherit via internal rule
, the block calculates the output word length and fraction length automatically. The internal rule first calculates an ideal output word length and fraction length using the following equations:Using these ideal results, the internal rule then selects word lengths and fraction lengths that are appropriate for your hardware. For more information, see Specify Fixed-Point Attributes for Blocks (DSP System Toolbox).
Lock data type settings against change by the fixed-point tools — Data type override
off (default) | on
Select this parameter to prevent the fixed-point tools from overriding the data
types you specify on the block mask. For more information, see fxptdlg
(Fixed-Point Designer), a reference page on the Fixed-Point Tool.
Block Characteristics
Data Types |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
More About
Fixed-Point Data Types
The following diagram shows the data types used in the 2-D DCT block for fixed-point signals. Inputs are first cast to the output data type and stored in the output buffer. Each butterfly stage processes signals in the accumulator data type, with the final output of the butterfly being cast back into the output data type.
The output of the multiplier is in the product output data type when at least one of the inputs to the multiplier is real. When both inputs to the multiplier are complex, the result of the multiplication is in the accumulator data type. For details on the complex multiplication performed, refer to Multiplication Data Types. You can set the sine table, product output, accumulator, and output data types in the block mask as discussed in the next section.
References
[1] Chen, W.H, C.H. Smith, and S.C. Fralick, “A fast computational algorithm for the discrete cosine transform,” IEEE Trans. Communications, 25 (1977): 1004-1009.
[2] Wang, Z. “Fast algorithms for the discrete W transform and for the discrete Fourier transform,” IEEE Trans. Acoust., Speech, Signal Processing, 32 (August 1984): 803-816.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)