written 6.1 years ago by | • modified 6.1 years ago |
JPEG compression steps in detail:-
• Step1: Converting the RGB image in to Grey scale image:
The original RGB color image is first converted to black and white image.
To compress a grey-scale image in JPEG, each pixel value is translated into grey value (0-255).
A color image is composed of pixels; these pixel values have RGB values, so to compress RGB color image, the work is three times as much because JPEG treats each color component separately.
The R (red) component is compressed first, the G (green) component and lastly B (blue) component.
The black and white image allows greater compression without a significant effect on image quality.
• Step2: Apply DCT (Discrete Cosine Transform):
In this step, grey scale image with 8*8 block image is divided into 8-pixel by 8-pixel block shown in Fig1 below.
Fig1: Input Matrix of DCT coefficient
This image is given as an input to DCT formula.
DCT Calculation:
The formula for discrete cosine transfer (creating DCT coefficient) is as follows:
$DCT (i,j) = \frac{1}{\sqrt{2N}} C(i) C(j) \sum \sum pixel (x,y) cos[\frac{(2x + 1) i \pi}{2N}] cos[\frac{(2y + 1) j \pi}{2N}]$ ---- (i)
The formula for inverse discrete cosine transform (restoring original pixel information from a DCT coefficient) is:
$Pixel (x,y) = \frac{1}{\sqrt{2N}} \sum \sum C(i) C(j) DCT (i,j) cos[\frac{(2x + 1) i \pi}{2N}] cos[\frac{(2x + 1) j \pi}{2N}]$ ---- (ii)
Then DCT coefficients are generated by applying DCT formula on 8*8 block using Equation 1 shown above.
After applying DCT formula, we will get 8*8 output matrix showing DCT coefficients as shown in Fig2 below.
Fig2: Output Matrix of DCT coefficient
• Step3: Quantization:
It is the process of reducing precision of an integer, thereby reducing the number of bits required to store the integer.
Quantization is the process to determine what information can be safely discarded with significant loss in visual fidelity.
The quantized coefficient is described by the following equation: Quantized coefficient (i, j) = DCT (i, j)/Quantum (i, j)
Quantized coefficient is result of dividing a DCT output matrix by a quantum matrix to generate quantized DCT values.
Typically, JPEG quantum matrix has large values in lower half of quantum matrix which in turn results in zero quantized coefficients in lower half of quantized matrix.
Quantized matrix is shown below in Fig3.
Therefore, matrix ends up with most DCT values as zeros and some non-zero DCT values.
• Step4: Zig-Zag sequence:
JPEG came up with ordering quantized DCT coefficient in zigzag sequence as shown in figure below.
After the quantization step, most of the coefficients towards the lower right corner are zero.
The zigzag ordering rearranges the coefficients in one dimensional order, in result most of the zeros will be placed at the end of the stream.
• Step5: Entropy encoding:
Entropy encoding is done using Huffman coding.
In Huffman coding, the most frequent character gets the smallest code and the least frequent character gets the largest code.