Software for Teaching and Learning
2D DCT and JPEG
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:
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.
The following learning objectives are associated with the above demonstration, with supporting lecture and possible programming assignment.