You are on page 1of 33

JPEG

Image Compression JPEG encoder schematic

The Joint Photographic Experts Group forms the basis of most video compression algorithms

Image Compression Image/block preparation


Source image is made up of one or more 2-D matrices of values

2-D matrix is required to store the required set of 8-bit grey-level values that represent the image
For the colour image if a CLUT is used then a single matrix of values is required If the image is represented in R, G, B format then three matrices are required If the Y, Cr, Cb format is used then the matrix size for the chrominance components is smaller than the Y matrix ( Reduced representation)

Image Compression Image/block preparation


Once the image format is selected then the values in each matrix are compressed separately using the DCT In order to make the transformation more efficient a second step known as block preparation is carried out before DCT In block preparation each global matrix is divided into a set of smaller 8X8 submatrices (block) which are fed sequentially to the DCT

Image Compression Image Preparation

Once the source image format has been selected and prepared (four alternative forms of representation), the set values in each matrix are compressed separately using the DCT

Image Compression Image Preparation

The values are first centred around zero by substracting 128 from each intensity/luminance value

Image Compression Image Preparation

Block preparation is necessary since computing the transformed value for each position in a matrix requires the values in all the locations to be processed

Image Compression Forward DCT


Each image is divided into 8 x 8 blocks. The 2D DCT is applied to each block image f(i,j), with output being the DCT coefficients F(u,v)/F(i,j) for each block If the input matrix is P[x,y] and the transformed matrix is F[u,v] then the DCT for the 8X8 block is computed using the expression:

1 (2 x 1)i (2 y 1) j F [i, j ] C (i)C ( j ) P[ x, y] cos cos 4 16 16


7 7 x 0 y 0

Image Compression Forward DCT


All 64 values in the input matrix f[i,j] contribute to each entry in the transformed matrix F[u,v] For u = v = 0 the two cosine terms are 0 and hence the value in the location F[0,0] of the transformed matrix is simply a function of the summation of all the values in the input matrix This is the mean of all 64 values in the matrix and is known as the DC coefficient

Since the values in all the other locations of the transformed matrix have a frequency coefficient associated with them they are known as AC coefficients

Image Compression Quantization

Using DCT there is very little loss of information during the DCT phase
The losses are due to the use of fixed point arithmetic

Image Compression Quantization

The main source of information loss occurs during the quantization and entropy encoding stages where the compression takes place The human eye responds primarily to the DC coefficient and the lower frequency coefficients (The higher frequency coefficients below a certain threshold will not be detected by the human eye)
This property is exploited by dropping the spatial frequency coefficients in the transformed matrix (dropped coefficients cannot be retrieved during decoding)

In addition to classifying the spatial frequency components the quantization process aims to reduce the size of the DC and AC coefficients so that less bandwidth is required for their transmission (by using a divisor)
The sensitivity of the eye varies with spatial frequency and hence the amplitude threshold below which the eye will detect a particular frequency also varies The threshold values vary for each of the 64 DCT coefficients and these are held in a 2-D matrix known as the quantization table with the threshold value to be used with a particular DCT coefficient in the corresponding position in the matrix

Image Compression Quantization

The choice of threshold value is a compromise between the level of compression that is required and the resulting amount of information loss that is acceptable
JPEG standard has two quantization tables for the luminance and the chrominance coefficients. However, customized tables are allowed and can be sent with the compressed image

Image Compression Quantization

Image Compression Quantization

Image Compression Example computation of a set of quantized DCT coefficients

Image Compression Example1 computation of a set of quantized DCT coefficients

Image Compression Example1 computation of a set of quantized DCT coefficients

Image Compression Example1 computation of a set of quantized DCT coefficients

Image Compression Example1 computation of a set of quantized DCT coefficients

Image Compression Quantization


From the quantization table and the DCT and quantization coefficents number of observations can be made: - The computation of the quantized coefficients involves rounding the quotients to the nearest integer value - The threshold values (quantization table) used increase in magnitude with increasing spatial frequency - The DC coefficient in the transformed matrix is largest - Many of the higher frequency coefficients are zero

Entropy encoding consists of four stages

Image Compression Entropy Encoding

Vectoring The entropy encoding operates on a onedimensional string of values (vector). However the output of the quantization is a 2-D matrix and hence this has to be represented in a 1-D form. This is known as vectoring

Differential encoding In this section only the difference in


magnitude of the DC coefficient in a quantized block relative to the value in the preceding block is encoded. This will reduce the number of bits required to encode the relatively large magnitude The difference values are then encoded in the form (SSS, value) SSS indicates the number of bits needed and actual bits that represent the value e.g: if the sequence of DC coefficients in consecutive quantized blocks was: 12, 13, 11, 11, 10, --- the difference values will be 12, 1, -2, 0, -1

Image Compression Vectoring using ZigZag scan

In order to exploit the presence of the large number of zeros in the quantized matrix, a zig-zag of the matrix is used

Image Compression run length encoding


The remaining 63 values in the vector are the AC coefficients
Because of the large number of 0s in the AC coefficients they are encoded as string of pairs of values Each pair is made up of (skip, value) where skip is the

number of zeros in the run and value is the next non-zero coefficient

The above will be encoded as


(0,6) (0,7) (0,3)(0,3)(0,3) (0,2)(0,2)(0,2)(0,2)(0,0) Final pair indicates the end of the string for this block

Image Compression Huffman encoding


Significant levels of compression can be obtained by replacing long strings of binary digits by a string of much shorter codewords

The length of each codeword is a function of its relative frequency of occurrence


Normally, a table of codewords is used with the set of codewords precomputed using the Huffman coding algorithm

Image Compression Frame Building


In order for the remote computer to interpret all the different fields and tables that make up the bitstream it is necessary to delimit each field and set of table values in a defined way The JPEG standard includes a definition of the structure of the total bitstream relating to a particular image/picture. This is known as a frame The role of the frame builder is to encapsulate all the information relating to an encoded image/picture

Image Compression Frame Building


At the top level the complete frame-plus-header is encapsulated between a start-of-frame and an end-of-frame delimiter which allows the receiver to determine the start and end of all the information relating to a complete image The frame header contains a number of fields - the overall width and height of the image in pixels - the number and type of components (CLUT, R/G/B, Y/Cb/Cr)

- the digitization format used (4:2:2, 4:2:0 etc.)

Image Compression Frame Building


At the next level a frame consists of a number of components each of which is known as a scan The level two header contains fields that include: - the identity of the components/scan - the number of bits used to digitize each component

- the quantization table of values that have been used to encode each component
Each scan comprises one or more segments each of which can contain a group of (8X8) blocks preceded by a header This contains the set of Huffman codewords for each block

Image Compression JPEG encoder

Image Compression JPEG decoder

A JPEG decoder is made up of a number of stages which are simply the corresponding decoder sections of those used in the encoder

JPEG decoding
The JPEG decoder is made up of a number of stages which are the corresponding decoder sections of those used in the encoder

The frame decoder first identifies the encoded bitstream and its associated control information and tables within the various headers It then loads the contents of each table into the related table and passes the control information to the image builder
Then the Huffman decoder carries out the decompression operation using preloaded or the default tables of codewords

JPEG decoding
The two decompressed streams containing the DC and AC coefficients of each block are then passed to the differential and run-length decoders

The resulting matrix of values is then dequantized using either the default or the preloaded values in the quantization table Each resulting block of 8X8 spatial frequency coefficient is passed in turn to the inverse DCT which in turn transforms it back to their spatial form
The image builder then reconstructs the image from these blocks using the control information passed to it by the frame decoder

JPEG Summary
Although complex using JPEG compression ratios of 20:1 can be obtained while still retaining a good quality image This level (20:1) is applied for images with few colour transitions For more complicated images compression ratios of 10:1 are more common Like GIF images it is possible to encode and rebuild the image in a progressive manner. This can be achieved by two different modes progressive mode and hierarchical mode

JPEG Summary
Progressive mode First the DC and low-frequency coefficients of each block are sent and then the highfrequency coefficients

hierarchial mode in this mode, the total image is first sent using a low resolution e.g 320 X 240 and then at a higher resolution 640 X 480

You might also like