You are on page 1of 46

3.

TEXT AND IMAGE COMPRESSION


INTRODUCTION. COMPRESSION PRINCIPLES. TEXT COMPRESSION. IMAGE COMPRESSION.

INTRODUCTION
In almost all multimedia application a technique known as compression is first applied prior to its transmission.

Why Do We Need Compression?


Requirements may outstrip the anticipated increase of storage space and bandwidth For data storage and data transmission - DVD - Video conference - Printer The bit rate of uncompressed digital cinema data exceeds 1 Gbps

COMPRESSION PRINCIPLES
Compression is done either to reduce the VOLUME of information to be transmitted ( text, fax or images) or to reduce the BAND-WIDTH that is required for its transmission. Different compression principles are:

Source encoders and Destination decoders.


Lossless and Lossy compression. Entropy encoding. Source encoding.

1. Source encoders and Destination decoders.


Compression algorithm and Decompression algorithm.

Source encoders and Destination decoders contd

2. Lossless and Lossy compression.

Lossless compression algorithm is used to reduce the amount of source information to be transmitted and to decompress the information without any losses. It is also called as REVERSIBLE.

Lossy compression algorithm does not reproduce an exact copy of the source information but rather a version of it which is perceived by the recipient as a true copy.

3. Entropy encoding.
It is a lossless and independent type of compression it is concerned with how the information is represented. It includes two widespread algorithm, they are: 1. Run-length encoding : Source information comprises long sub-strings of same character or binary digit.

2. statistical encoding : It exploits the property of using a variable length code words. In this encoding the destination must aware of code words set. A code word set that avoids the wrong code word is said to posses the PREFIX PROPERTY.
HAFFUMAN CODING is the better example of having a prefix property.

Minimum average number of bits that are required to transmit a source stream is known as ENTROPY and can be coded by using SHANNON ENTROPY formula.

entropy (H)=

Pi log 2 (Pi)

N number of different symbols


Pi probability of occurrence of symbol I. Efficiency is the ratio of entropy of source to the average number of bits per codeword Average number of bits per codeword is = Problem (1) pg no. 142 Ni Pi

4. Source encoding.
It uses an alternative form of representation of a compressed version of original information. This can be used in two ways, they are:

1. Differential encoding.

2. Transform encoding.

DIFFERENTIAL ENCODING: in this type of encoding, instead of using a set of relatively large code words, a set of small code words is used which indicates only the difference in amplitude between the current value and the next Immediately preceding value.

TRANSFORM ENCODING: involves transforming the source from one form into another

Rate of change in magnitude as one transverses the matrix gives rise to a term known as SPATIAL FREQUENCY. DISCRETE COSINE TRANSFORM (DCT) is used as mathematical analysis for transferring of 2-D matrix.

TEXT COMPRESSION: All the three types of text are represented as string of characters selected from a defined set. any compression algorithm associated with text must be lossless .

text compression uses statistical encoding.


For the text compression this statistical encoding can be used in mainly in three types, they are

HUFFMAN CODING
ARITHMETIC CODING LEMPEL-ZIV (LZ) CODING

HUFFMAN CODING
Huffman coding is a type of text compression which can be clearly analyzed by static Huffman coding and Dynamic Huffman coding .
STATIC HUFFMAN CODING: character string is first analyzed and their relative frequency is determined. Coding involves creating an unbalanced tree with some branches shorter than others. DYNAMIC HUFFMAN CODING:

ARITHMETIC CODING

Huffman coding achieves shannon value only if the character or the symbol are all integers of (1/2). And set codeword obtained are optimum
ARITHMETIC CODING results a set of codewords sent as a block of data known as binary arithmetic coding.

LEMPEL-ZIV CODING
Instead of using a single character we are using a strings of characters. The occurrence of the character in the text to be transmitted is held by both the encoder and decoder in a table. This table is used as dictionary and the LZ algorithm is known as Dictionary based compression algorithm.

LEMPEL-ZIV- WELSH CODING


This algorithm is used to build the contents of the dictionary dynamically as the text being transferred . Initially the encoder and decoder uses the character that has been used to create the text. The remaining entries are then built up dynamically by both ( the encoders and decoders ).

IMAGE COMPRESSION:Images are of two types, they are: 1. Computer generated (Graphical) images are represented via a form of program written in a particular graphics programming languages.

2. Digitized images (both document & picture) 2-D matrix representation is used.

There are several formats used to compress the image and are sent via a network to the destination. Mainly run length and statistical coding, transform and differential coding is used.

Graphics Interchange Format :It is used extensively with the INTERNET for the representation and compression of the graphical images. The color images uses 24 pels of 8-bits each for R,G and B by selecting 256 colors from the original set. Instead of sending each pels as a 24-bit value only 8-bit index to the table entry is sent.

This table of colors relate either to the whole image {global color table} or to a portion of the image (local color table}. LZW coding algorithm is used.

Dynamic mode using LZW coding

Tagged Image File Format :It supports the pixel resolution of 48-bits, 16-bits each for R,G and B colors. Same LZW compression is used as in the GIF. color table containing 256colors and the table can be extended up to 4096 entries.

DIGITIZED DOCUMENT :Scanned lines consist only of long strings of white picture element while other comprise a mix of long strings of white pels and long string of black pels. Facsimile machie is the best example of this format.

ITU-T has produced standards they are: 1. T2(group1) 2. T3(group2) 3. T4(group3) 4. T6(group4).

DIGITIZED DOCUMENT contd.. :Codeword are fixed and grouped in to 2 separate tables, they are 1. The termination code table: are for white and black run-length of from 0 to 63 pels 2. Make-up codes table : code words for white or black run length that are multiples of 64 pels
Run-length coding are associated with a coding line as one of the three possibilities or modes they are 1. Pass mode. 2. vertical mode. 3. horizontal mode.

DIGITIZED PICTURE :The most widely adopted standard relating to the compression of digitized picture has been introduced by an international standard body known as Joint Photographic Experts Group (JPEG).

JPEG :It is a standard that was developed by a team of experts working on behalf of ISO, The ITU, & the TEC. JPEG is defined in the international standards IS10918. JPEG defines a number of format (modes), we will study only the lossy sequential mode used in this case. This mode is also known as BASELINE MODE.

Flow chart.

JPEG contd.. :-

JPEG contd.. :There are 5 different stages associated with this mode, they are
1. Image / block representation. 2. Forward DCT. 3. Quantization. 4. Entropy encoding .

5. Frame building

1. Image / block representation.

Image preparation

Block preparation

2. Forward DCT

P[x,y] is the input 2-D matrix. F[i,j] is the transformed matrix. C(i) and c(j) = For I,j=0

= 1 for all other value of I & j.

2. Forward DCT contd..


The following steps are remembered during the DCT: 1. All 64 values in the input p[x,y] contributes to each entry in the transformed matrix f[i,j]. 2. For i=j=0, two cosine terms are 0. the value in the location f[0,0] of the transformed matrix is a summation of all the values in the input. It is the mean of all the values in the matrix and is known as DC-COEFFICIENTS. 3. All the other values has the coefficients either in horizontal (x=1-7 for y=0), vertical (x=0 for y=1-7)or both (x=1-7 for y=1-7) they are known as AC-COEFFICIENTS

2. Forward DCT contd..


4. If j=0, only horizontal frequency components are presented for i=1-7. If i=0, only vertical frequency components are presented for j=1-7. 5. In other loaction both horizontal and vertical frequency components are present to varying degree.

3. Quantization
The quantization process aims to reduce the size of the DC and AC co-efficient, so that the less bandwidth is required for transmission. To determine whether a particular spatial frequency coefficient is above a defined threshold quantization is carried out.

Following are the certain constraints for quantization:


1. Computations of the quantized co-efficient involves rounding the quotients to the nearest integer value.

2. threshold values used increases in magnitude with increasing spatial frequency.


3. DC co-efficient in the transformed matrix is largest. 4. Many of the higher frequency co-efficient are zero.

Example: assuming a quantization threshold value of 16, derive the resulting quantization error for each of the following DCT co-efficient of 127,72,64,56,-56,-64,-72,-128. Coefficient 127 Quantized Rounded Dequantized Error value value value 127/16=7 8 128 -1 .937

72
64 56 -56 -64 -72 -128

4.5
4 3.5 -3.5 -4 -4.5 -8

5
4 4 -4 -4 -5 -8

80
64 64 -64 -64 -80 -128

-8
0 8 -8 0 -8 0

4. Entropy Encoding
This stage comprises 4 steps, they are:

1. Vectoring
2. Differential encoding 3. Run-length encoding 4. Huffman encoding

5. Frame Building
Frame building is to encapsulate all the information relating to an encoded image / picture. It consists of the parameters like, at the top level the complete frame plus header is encapsulated between a start of frame and a end of frame.

5. Frame Building contd..


Frame header contains: 1. Overall width and height of the image in pixels.

2. Number & type of component that are used to represent the image (CLUT, R/G/B, Y/Cb/Cr).
3. Digitization format used (4:2:2, 4:2:0). At second level the frame consist of : 1. Identity if the components used.

2. Number of bits used to digitize each component.


3. Quantization table of values that have been used to encode each component.

JPEG Decoding:

JPRG Decoding contd


1. Frame decoder first identifies the control information and tables with in the various header. 2. Loads the content of each table into the related table and passes to the image builder. 3. Start to pass the compressed bit stream to the huffman decoder. 4. Decompressed signal are differentiated into separate DC and AC coefficients. Using differential and run length decoders. 5. Resulting matrix is the dequantized value in quantization table. 6. Each resulting block of 8*8 spatial frequency is passed through inverse DCT and performs decoding operation on the basis of:

Finally as with GIF, it is also encoded and rebuild the image in a progressive way by sending an outline of the image in two ways: 1. Progressive mode: DC and low frequency components of each block are sent and then higher frequency component is used. 2. Hierarchical mode: total image is sent first using low resolution i.e for 320*420, then at a higher resolution such as 640*480.

You might also like