Software for Teaching and Learning


The 2-D Discrete Cosine Transform is similar to a Fourier transform but uses purely real math. It also has purely real transform domain coefficients and incorporates strictly positive frequencies.As such it is simpler to evaluate than the Fourier transform and has become the transform of choice in image compression standards such as JPEG. The JPEG approach breaks an image into 8x8 tiles, each of which is transformed, quantized and encoded separately.

Input image for 2D DCT.

Transform domain coefficients. Only a few components are visible for each 8x8 block. The DC component is in the upper left of each block.

Image of flowers after quantizing transform coefficients and performing an inverse 2D DCT. Note the block structure is clearly evident. Compression in this case was 17.8:1 with an SNR of 20.1 dB. Note this did not include zero run length coding of the AC coefficients.

The version of the 2D DCT in this demo does include forward and inverse transform, with quantization. The level of quantization varies with each coefficient, following the JPEG standard. The demo does not include zero run length encoding associated with the quantized AC components, as given in JPEG. (Compression ratio found via an entropy calculation only). Hence compression ratios and SNR values are not quite as good as may be obtained with the full version of the JPEG algorithm.

The demo permits the quantization level to be adjusted, affecting compression ratio and SNR. A range of degradation is possible, and a difference image is computed.

Users may zoom into the image of the quantized and unquantized coefficients, to observe differences.

Suggestions for a lecture & demonstration:

  • Explain DCT with transform definitions and describing basis functions (not included in demo).
  • Describe JPEG processing steps, and show forward transform before and after quantization.
  • Zoom into a given section of the transform plane and show differences in intensity levels (and zeroing) of transform coefficients. Show DC and low frequency coefficients.
  • Apply different quantization levels and show resulting errors in image, and image difference.
  • Show tradeoff between compression ratio and SNR, changing quantization level.

A presentation is also available that discusses a hardware design of a DCT that optimizes the precision of multiplier units. Reduced precision of the multiplication results in quantization of the transform coefficients. As quantization is desirable, this offers a method of optimizing the hardware design.

Download 2D DCT Demonstration


Learning Objectives

The following learning objectives are associated with the above demonstration, with supporting lecture and possible programming assignment.

Compute the entropy of a given signal.
Compute a 1-D and 2-D DCT
Quantize coefficients.
Understand and apply the steps JPEG algorithm.
Compute a SNR value, given example data. Compute a compression ratio.
Understand the tradeoff between compression and SNR.