Discrete Cosine Transform: A General Algorithim For DCT Compression With This Class
Discrete Cosine Transform: A General Algorithim For DCT Compression With This Class
The DCT is a mathematical transformation that takes a signal and transforms it from spatial domain
into frequency domain. Many digital image and video compression schemes use a block-based DCT,
because this algorithm minimizes the amount of data needed to recreate a digitized image. In
particular, JPEG and MPEG use the DCT to concentrate image information by removing spatial data
redundancies in two-dimensional images.
The DCT works by separating images into parts of differing frequencies. During a step called
quantization, where part of compression actually occurs, the less important frequencies are
discarded. Then, only the most important freqencies that remain are used to retrieve the image in
the decompression process. As a result, reconstructed images may contain some distortion.
Quantization
Quantization is achieved by dividing each element in the transformed image matrix D by the
corresponding element in the quantization matrix, and then rounding to the nearest integer value.
As for quantization, we can choose the quality range from 1 (the poorest quality, best compression)
to 100 (best quality, worst compression). In here i use quality 50.
Di , j
Ci , j =round
( )
Qi, j
A general algorithim for DCT decompression with this class:
Reconstruction begins by decoding the bit stream representing the quantized matrix C and multiply
with the corresponding element of quantization matrix originally used. This is what we call
dequantitize process.
After that we apply the Inverse DCT to matrix R, round the to the nearest integer and add 128 to
each element.