Unit 3
Unit 3
❖ In order for the destination to reproduce the original source information or, in some instances, a nearly
exact copy of it a matching decompression algorithm must be applied to it.
❖ The application of the compression algorithm is the main function carried out by the source encoder.
❖ The application of the decompression algorithm is the main function carried out by the destination
decoder.
❖ In applications which involve two computers communicating with each other, the time required to
perform the compression and decompression algorithms is not always critical both algorithms are
normally implemented in software within the two computers as shown in figure below.
❖ An application which uses this approach is the compression of text and/or image files.
❖ The aim is to reduce the amount of source information to be transmitted in such a way that, when the
compressed information is decompressed, there is no loss of information.
❖ Ex.: transfer of a text file over a network, since no, part of the source information is lost during either
the compression or decompression operations.
Lossless compression algorithm:
❖ The aim is normally not to reproduce an exact copy of the source information after decompression
but rather a version of its which is perceived by the recipient as a true copy.
❖ With such algorithms the higher level of compression being applied to the source information the
more approximate the received version becomes.
❖ Ex.: transfer of digitized images, audio and video streams. In such cases, the sensitivity of the
human eye or ear is such that any fine details that may be missing from the original source signal after
decompression are not detectable.
Entropy encoding:
It is lossless and independent of the type of information that is being compressed.
Concerned solely with how the information is represented.
Ex.: Run-length encoding and Statistical encoding.
Run-length encoding:
Typical applications: When source information comprises long substrings of the same character or
binary digit.
Here, instead of transmitting source string in the form of independent codewords or bits source
string is transmitted in the form of different set of codewords which indicates:
Particular character or bit being transmitted and
Number of characters/bits in the substring
Providing the destination to know the set of codewords being used destination simply, interprets
each codeword received and outputs the appropriate number of characters or bits.
Ex.: An application involves transmission of long strings of binary bits that comprise limited number
of substrings.
Each substring can be assigned a separate codeword, total bit string is then transmitted in the form
of the string of codewords selected from the codeword set.
Ex.: Transmission of the binary strings produced by the scanner in a facsimile machine.
When scanning typed documents in many instances scanner produces long substrings of either
binary 0s or 1s.
Instead of transmitting directly, they are sent in the form of a string of codewords each indicating
both the bit 0 or 1 and the number of strings in the substring.
Page No - 3 M3
Ex.: if the output of the scanner was 000000011111111110000011… then it can be represented as
(0,7) (1,10) (0,5)(1,2) …
Since, only the two binary digits 0 and 1 are involved and if, first substring always comprises binary 0s
then, the string could be represented as 7, 10, 5, 2 …
To send this in the digital form, individual decimal digits would be sent in their binary form.
Assuming the fixed number of bits per codeword number of bits per codeword would be determined
by the largest possible substring.
Statistical encoding:
Applications use a set of codewords to transmit the source information.
Ex.: Set of ASCII codewords are often used for the transmission of strings of characters.
Normally, all the codewords in the set comprise a fixed number of binary bits.
Ex.: 7 bits in the case of ASCII.
In many applications: Symbols (characters) and hence codewords that are present in the source
information do not occur with the same frequency of occurrence, that is with equal probability.
Ex.: Consider a string of text in which character A may occur more frequently than character P which
again, will occur more frequently than character Z, and so on.
Statistical encoding exploits this property by using the set of variable length codewords, with the
shortest codewords used to represent the most frequently occurring symbols.
Use of variable-length codewords is not quite as straight-forward. Destination must know the set of
codewords being used by the source as in run-length encoding.
When variable-length codewords used, in order for the decoding operation to be carried out
correctly. It is necessary to ensure that a shorter codeword in the set does not form the
start/beginning of a longer codeword otherwise; the decoder will interpret the string on the wrong
codeword boundaries.
Prefix property codeword set are used, which avoids the above happening.
Ex.: Huffman encoding algorithm.
Source entropy: Theoretical minimum average number of bits that are required to transmit a
particular source stream and is given by Entropy,
Static coding:
Intended for applications in which the text to be compressed has known
characteristics in terms of the characters used and their relative frequencies of
occurrence.
type of text.
In this case, optimum set of codewords also likely to vary from one transfer to
another.
Codeword set used to transfer a particular text string is derived as the transfer takes
place this can be done by building up knowledge of both the characters that are
present in the text and their relative frequency of occurrence dynamically as the
characters are being transmitted.
Codewords used change as a transfer takes place in such a way that receiver is able
to dynamically compute the same set of codewords that are being used at each point
during a transfer.
● As each branch divides binary value 0 of 1 are assigned to each new branch a 0 for left
and 1 for right.
● Codewords used for each character (shown in leaf nodes) are got by tracing the path
from root node to each leaf node and forming a string of binary values associated with
each branch traced.
● Set of codes associated with this tree is 4*1+2*2+1*3+1*3=14bits is required to transmit
the complete string – AAAABBCD.
● Figure below shows Huffman tree with information frequency of occurrence of each
characters here characters listed in a column in decreasing weight order.
Tree construction:
● Huffman tree can be constructed from the set of codewords, the actual codewords,
however start at the root and not the leaf node.
● Optimality check for tree (hence for Codewords):
1. Listing the resulting weights of all the leaf and branch nodes in the tree starting
with the smallest weight and proceeding from left to right and from bottom to
top.
M3
2. Tree is optimal if the resulting list increments in weight order.
● Each character in its encoded form has a variable number of bits; received bitstream
must be interpreted (decoded) in a bit-oriented way rather than on fixed 7/8 bit
boundaries.
● Shorter codeword will never form the start of a longer codeword which is a prefix
property.
● Prefix property: received bitstream can be decoded by carrying out a recursive search
bit by bit until each valid codeword is found.
Decoding Algorithm:
● Figure below shows the flowchart of a decoding algorithm.
● Assumption: Table of codewords are available at the receive and also had
corresponding ASCII codeword.
● Huffman code tree and hence, codewords varies for different sets of characters being
transmitted for the receiver to perform the decoding operation, it must know the
codewords relating to the data being transmitted can be done in 2 ways:
1. Codewords relating to the next set of data are sent before the data is transmitted.
▪ Here the receiver to have one or more different sets of codewords and
Sender to indicate to the receiver through an agreed message which
codeword set to use for the next set of data.
The Huffman code tree corresponding to the derived set of code-words is given in Figure
below and, as we can see, this is the optimum tree since all leaf and branch nodes
increment in numerical order.
(a) Average number of bits per codeword using Huffman coding is:
2(2×0.25) + 2(3×0.14) +4(4×0.055)= 2.72 bits per codeword which is 99.8% of the
Shannon value.
Using fixed-length binary codewords:
There are 8 characters –A through H – and hence 3 bits per codeword is sufficient which
is 90.7% of the Huffman value.
Using 7-bit ASCII codewords:
7 bits per codeword which is 38.86% of the Huffman value.
ENCODER: DECODER:
Initial_code (); initial_code();
While not EOF while not EOF
{ {
Get(c); decode(c);
Encode(c); output(c);
Update_tree(c); update_tree(c);
} }
● Initial_code assign symbols with some initially agreed upon codes, without any prior
knowledge of the frequency counter for them.
● Update_tree is a procedure for constructing an adaptive Huffman tree. It does two
things: it increments the frequency counts for the symbols and updates the
configuration of the tree.
● The Huffman tree must always maintain its “Sibling Property”- that is, all nodes are
arranged in the order from Left to Right, Bottom to Top.
ADVANTAGES:
1) Saving in transmission bandwidth start only when characters begin to repeat
themselves. Savings with text files can be significant.
2) Used in number of common applications that involves the transmission of text.
3)
Arithmetic Coding:
● Huffman coding achieves the Shannon value only if the character/symbol probabilities are
all integer powers of 1/2.
● In contrast, the codeword produced using arithmetic coding always achieve the Shannon
value.
● It yields a Single Codeword for each encoded string of characters however Huffman
coding yields a single codeword for each encoded characters in a string.
● Arithmetic coding, however, is more complicated than Huffman coding.
● Algorithm:
BEGIN:
Low = 0.0; high 1.0; range = 1.0; While (Symbol != terminator)
{
get (Symbol);
Low = low + range x range_low (Symbol); High = low + range x range_high
(Symbol); range = high – low;
}
Output a code so that low ≤ Code < high; END
● Calculations:
High=low+(range × range_high(symbol))
Problems on Arithmetic Coding:
e = 0 + (0.3 * 0.3) =
0.09 n = 0.09 + (0.3 *
0.3) = 0.18
t = 0.18 + (0.3 * 0.2) = 0.24
w = 0.24 + (0.3 * 0.1) = 0.27
. = 0.27 + (0.3 * 0.1) = 0.3
3) To transmit ‘n’, range= 0.216 - 0.198= 0.018
• Therefore, the codeword for the string ‘etnw.’ should lie in the range given below:
0.2124 ≤ codeword ≥ 0.2142
• Any value sent between the above range will be interpreted as the string ‘etnw.’
Decoding Process:
• The decoder knows the set of characters that are present in the encoded messages it
receives as well as the segment to which each characters has been assigned and its
related range (i.e., probability distribution).
• Taking this string as a starting point, the decoder can follow the same procedure as that
followed by the character string relating to each received codeword.
• Ex: say the received codeword = 0.81611.
• Seeing the above output decoder interprets 1st character as ‘w’ since it is in the range of
0.8 to 0.9.
• It then expands the above interval further and determines that the 2nd character is ‘e’ as
0.8161 as it is in the range 0.8 to 0.833.
• The decoder repeats the process until it decodes the terminator character then it stops.
Precision Issue:
• In this coding, number of decimal digits in the final codeword increases linearly with
the number of character in the string to be encoded.
• Maximum number of characters in a string is determined by the precision with which
floating numbers are represented in the source and destination computers.
• Thus, a complete message may be first fragmented into multiple smaller strings.
• Each string is then encoded separately and the resulting set of codewords is sent as a
block of floating-point number each in a known format.
Lempel-Ziv coding:
• Advantage:
As each word occurs in the text, instead of sending the word as a set of individual
ASCII codewords, the encoder sends only the index of where the word is stored in
the table and, on receipt of each index, the decoder uses this to access the
corresponding word/string of characters from the table and proceeds to
reconstruct the text into its original form.
• Scenario:
Most word processing packages have a dictionary associated with them which is
used for both spell checking and for the compression of text. Typically, they
contain 25000 words and hence 15bits which has 32768 combinations are
required to encode the index.
To send the word “multimedia” with such a dictionary would require just 15 bits
instead of 70 bits with 7-bit ASCII codewords. This results in a compression ratio
of 4.7:1.
From above we can analyze that shorter words will have a lower compression
ratio and longer words have a higher ratio.
• Requirement:
1. A copy of the dictionary is held by both the encoder and the decoder.
2. Above is acceptable for the transmission of text which has been created using a
standard word-processing package.
• Limitation:
Lempel-Ziv-Welsh coding:
• Principle of operation:
Here encoder and decoder will build the contents of the dictionary dynamically
as the text is being transferred.
Initially, the dictionary held by both the encoder and decoder contains only the
character set example ASCII that has been used to create the text.
The remaining entries in the dictionary are then built up dynamically by both the
encoder and decoder and contain the words that occur in the text.
• Scenario:
Let the character set comprises 128 characters and the dictionary is limited to,
say, 4096 entries, then the first 128 entries would contain the single characters
that make up the character set and the remaining 3968 entries would each
contain strings of two or more characters that make up the words in the text
being transferred.
The more frequently the words stored in the dictionary that occur in the text, the
higher the level of compression.
In order to describe how the dictionary is built up, let us assume that the text to
be compressed starts with the string:
This is simple as it is…..
Since the idea is for the dictionary to contain only words, then only strings of
characters that consist of alphanumeric characters are stored in the dictionary
and all the other characters in the set are interpreted as word delimiters.
Initially, the dictionary held by both the encoder and decoder contains only the
individual characters from the character set being used; for example, the 128
characters in the ASCII character set.
The first word in the example text is sent by the encoder using the index of each
of the four characters T,h,i and s.
When the encoder reads the next character from the string the first space (SP)
character it determines that this is not an alphanumeric character. It therefore
transmits the character using its index as before but, in addition, interprets it as
terminating the first word and hence stores the preceding four characters in the
next available (free) location in the dictionary.
In the same way decoder, on receipt of the first five indices/codewords, reads the
character stored at each index and commences to reconstruct the text.
When it determines that the fifth character is a space character, it interprets this
as a word delimiter and proceeds to store the word This in its dictionary.
The same procedure is followed by both the encoder and decoder for transferring
the other words except the encoder, prior to sending each word in the form of
single characters, first checks to determine if the word is currently stored in its
dictionary and, if it is, it sends only the index for the word.
Similarly the decoder, since it also has the word stored in its dictionary, uses the
index to access the string of characters that make up the word.
Thus with the example text string, after the space character following the second
occurrence of the word is, the contents of the dictionary held by both the encoder
and the decoder will be as shown in Figure below. As we can see, since this is the
second occurrence of the word is, it is transferred using only the index of where it
is stored in the dictionary (129).
• Accuracy Assessment:
As we can deduce from this example, a key issue in determining the level of
compression that is achieved, is the number of entries in the dictionary since this,
in turn, determines the number of bits that are required for the index.
With a static dictionary, the number of entries is fixed and, for the example we
identified earlier, a dictionary containing 25000 words requires 15 bits to encode
the index.
When building the dictionary dynamically, however, the question arises as to how
many entries should be provided for the dictionary.
Clearly, if too few entries are provided then the dictionary will contain only a
subset of the words that occur in the text while if too many are provided, then it
will contain empty spaces which, in turn, makes the index unnecessarily long.
In order to optimize the number of bits used for the index, at the commencement
of each transfer the number of entries is set to a relatively low value but, should
the available space become full, then the number of entries is allowed to increase
incrementally.
E.x., in an application that uses 128 characters in the basic character set, then
both the encoder and decoder would start with, say, 256 entries in the dictionary.
When this number of locations becomes insufficient, on detecting this, both the
encoder and decoder would double the size of their dictionary to 512 locations.
Clearly, this necessitates an index length of 9 bits and so from this point, the
encoder uses 9-bit codewords.
However, since the decoder had also doubled the size of its own directory, it
expects 9-bit codewords from this point.
In this way, the number of entries in the dictionary more accurately reflects the
number of different words in the text being transferred and hence optimizes the
number of bits used for each index/codeword.
In this example it is assumed that the last entry in the existing table at location
255 is the word fish and the next word in the text that is not currently in the
dictionary is pond.
1 A
2 B
3 C
Now if the input string is “ABABBABCABABBA”, the LZW compression algorithm works as follows:
S C Output Code string
1 A
2 B
3 C
---------------------------------------------------------------------------------------------------------------------
A B 1 4 AB
B A 2 5 BA
A B
AB B 4 6 ABB
B A
BA B 5 7 BAB
B C 2 8 BC
C A 3 9 CA
A B
AB A 4 10 ABA
A B
AB B
ABB A 6 11 ABBA
A EOF 1
The output codes are: 1 2 4 5 2 3 4 6 1. Instead of sending 14 characters, only 9 codes need to
be sent (compression ratio = 14/9 = 1.56).
ALGORITHM (Decompression):
BEGIN s = NIL;
while not EOF
{
k = next input code; entry = dictionary entry for k; output
entry; if (s != NIL) add string s + entry[0] to dictionary with a new code; s
= entry; } END Problem:
2. Input codes to the decoder are 1 2 4 5 2 3 4 6 1. Decode the string using LZW algorithm.
The initial string table is identical to what is used by the encoder.
Solution:
1 A
2 B
3 C
NIL 1 A
A 2 B 4 AB
B 4 AB 5 BA
AB 5 BA 6 ABB
BA 2 B 7 BAB
B 3 C 8 BC
C 4 AB 9 CA
AB 6 ABB 10 ABA
ABB 1 A 11 ABBA
A EOF
Let’s start with a very simple dictionary (also referred to as a “string table”), initially containing
only 3 characters, with codes as follows:
Code String
1 A
2 B
3 C
4 E
Solution: Now if the input string is “ABCBCABCEAB”, the LZW compression algorithm works as
follows:
S C Output Code String
1 A
2 B
3 C
4 E
--------------------------------------------------------------------------------------------------------------------
A B 1 5 AB
B C 2 6 BC
C B 3 7 CB
B C
BC A 6 8 BCA
A B
AB C 5 9 ABC
C E 3 10 CE
E A 4 11 EA
A B
AB EOF 5
The output codes are: 1 2 3 6 5 3 4 5. Instead of sending 11 characters,
only 8 codes need to be sent (compression ratio = 11/8 = 1.375).
4. Compress the following string “MYMEMYMO” using LZW Algorithm
Solution: Let’s start with a very simple dictionary (also referred to as a “string table”), initially
containing only 4 characters, with codes as follows:
Code String
1 M
2 Y
3 E
4 O
Now if the input string is “MYMEMYMO”, the LZW compression algorithm works as follows:
1 M
2 Y
3 E
4 O
M Y 1 5 MY
Y M 2 6 YM
M E 1 7 ME
E M 3 8 EM
M Y
MY M 5 9 MYM
M O 1 10 MO
O EOF 4
The output codes are: 1 2 1 3 5 1 4. Instead of sending 8 characters, only 6 codes need to be
sent (compression ratio = 8/6 = 1.33).
Decoding:
• Input codes to the decoder are 1 2 1 3 5 1 4 . Decode the string using LZW algorithm.
2 Y
3 E
4 O
NIL 1 M
M 2 Y 5 MY
Y 1 M 6 YM
M 3 E 7 ME
E 5 MY 8 EM
MY 1 M 9 MM
M 4 O 10 MO
O EOF
The output string is “ MYMEMYMO ”.
Image Compression:
• Images can be of two basic types:
1. Computer-generated (also known as graphical) images and
2. Digitized images (of both documents and pictures).
• Both types are displayed (and printed) in the form of a two-dimensional matrix of
individual picture elements, but a graphical image is represented differently in the
computer file system.
• As, this is in the form of a program this type of representation requires considerably less
memory (and hence transmission bandwidth) than the corresponding matrix of picture
elements, whenever possible, graphics are transferred across a network in this form.
• Digitized documents and pictures, however, once digitized, the only form of
representation is as a two-dimensional matrix of picture elements.
• With respect to compression:
1. When transferring graphical images which are represented in their program
form, a lossless compression algorithm must be used.
2. When the created image/graphic is to be transferred across the network in its
bit- map form, then this is normally compressed prior to its transfer.
• To transfer digitized images two types of compression algorithm normally are
employed:
1. A combination of run-length and statistical encoding. It is lossless and is used for
the transfer of the digitized documents generated by scanners such as those used
in facsimile machines.
2. A combination of transform, differential, and run-length encoding and has been
developed for the compression of both bitonal and color digitized pictures.
• From the figure above we see that, the LZW coding algorithm can be used to obtain
further levels of compression.
• This works by extending the basic color table dynamically as the compressed image data
is being encoded and decoded. As long strings of the same color — are detected, these
are entered into the color table after the 256 selected colors.
• In this application, since each entry in the color table comprises 24 bits, in order to save
memory, to represent each string of pixel values just the corresponding string of 8-bit
indices to the basic color table are used.
• Normally, since the basic table contains 256 entries, an initial table size of 512 entries is
selected which allows for up to 256 common strings to be stored.
• As with text compression, however, should more strings be found, then the number of
entries in the table is allowed to increase incrementally by extending the length of the
index by 1 bit as shown below.
• GIF also allows an image to be stored and subsequently transferred over the network in
an interlaced Mode.
• This can be useful when transferring images over either low bit rate channels or the
Internet which provides a variable transmission rate.
• With this mode, the compressed image data is organized so that the decompressed
image is built up in a progressive way as the data arrives.
• To achieve this, the compressed data is divided into four groups as shown in Figure
below and, as we can see, the first contains 1/8 of the total compressed image data, the
second a further 1/8, the third a further 1/4, and the last the remaining 1/2.
4. Entropy Encoding
5. Frame Building
• Developed by ISO and ITU-T for United Nation Figure below shows Encoder
schematic
Image/block preparation:
• The source image is made of one or more 2-D matrices of values.
• For continuous tone monochrome image, a single 2-D matrix is required to store the set
of 8-bit grey level values that represent the images.
• For color image, if a CLUT is used just a single matrix of values is required.
• If the image is represented in an R, G, B format three matrices are required, one each for
the R, G, and B quantized values.
• For color images the alternative form of representation known as Y, Cb, Cr can optionally
be used.
• The above representation in turn allows the two matrices that contain the digitized
chrominance components to be smaller in size than the Y matrix so producing a reduced
form of representation over that of R, G, B form.
• The four alternative forms of representation are as shown in figure above.
• Once the source image format has been selected and prepared, the set of values in each
matrix are compressed separately using the DCT.
• But before performing the DCT on each matrix, another step known as block preparation
is carried out.
• It would be too time consuming to compute the DCT of the total matrix in a single step so
each matrix is first divided into a set of smaller 8 x 8 sub matrices.
• Each is known as block and is fed sequentially to the DCT which transforms each block
separately as shown below.
Forward DCT:
Transforms the pixel information from spatial domain to frequency domain with the DCT.
• Each pixel value is quantized using 8 bits which produces a value in the range 0 to 255
for the intensity values — R, G, B or Y.
• The value in the range —128 to +127 for the two chrominance values— Cb and Cr.
• To compute DCT, however, all the values are centered around zero by subtracting 128
from each intensity values.
• Then, if the input 2-D matrix is represented by : P[x,y] and the transform matrix is
F[i,j],then DCT of each 8 x 8 block f values is computed by:
for i , j=0
Here C(i) and C(j) =
=1 for all other values of i and x, y, i , and j all vary from 0 through 7.
• Consider a typical image say of 640 x480 pixels.
• If block size is 8 x 8 pixels, then image will have 80 x 60 or 4800 block each of which, for
a screen width of say, 16 inches (400 mm), will occupy a square of only 0.2x0.2 inches
(5x 5 mm).
• Those regions of picture that contains a single color will generate a set of transformed
blocks all of which will have firstly, the same DC coefficient and secondly AC coefficient
with them.
• Also only those areas of picture which contain color transition that will generate a set of
transformed blocks with different DC coefficient and a large number of AC coefficients
with them.
• The above features are exploited in the quantization and entropy encoding phases of the
compression algorithm.
Quantization:
• The values from the DCT are initially floating point; they are change to integers by
quantization.
• During the DCT phase there is very little loss of information the main source of
information loss occurs during the quantization and entropy encoding stages where the
compression takes place.
• Human eye responds primarily to the DC coefficient and the lower spatial frequency
coefficients i.e. having higher magnitude volume.
• If the magnitude of a higher frequency coefficient is below a certain threshold, the eye
will not detect it.
• The above property is exploited in the quantization phase by dropping those spatial
frequency coefficients in the transformed matrix whose amplitudes are less than a
defined threshold value.
• Quantization process aims to reduce size of the DC and AC coefficients so that less
bandwidth is required for their transmission.
• For the above point a division operation is performed using the defined threshold value
as the divisor.
• If the resulting (rounded) quotient is zero, the coefficient is less than the threshold
value. If it is non-zero, this indicates the number of times the coefficient is greater than
the threshold rather than its absolute value.
• The sensitivity of the eye varies with spatial frequency, which implies that the amplitude
threshold below which the eye will detect a particular spatial frequency also varies.
• Threshold values used vary for each of the 64 DCT coefficients which are held in a two-
dimensional 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.
• The choice of threshold values is important and, in practice, is a compromise between
the level of compression that is required and the resulting amount of information loss
that is acceptable.
• JPEG standard includes two default quantization table values:
1. One for use with the luminance coefficients and
2. The other for use with the two sets of chrominance coefficients.
• It also allows for customized tables, to be used and sent with the compressed image.
• An example set of threshold values is given in the quantization table shown in Figure
below together with a set of DCT coefficients and their corresponding quantized values.
• Number of points can be concluded from the values shown in the tables:
1. The computation of the quantized coefficients involves rounding the quotients to
the nearest integer value.
2. The threshold values used, in general, increase in magnitude with increasing
spatial frequency.
3. The DC coefficient in the transformed matrix is largest.
4. Many of the higher-frequency coefficients are zero.
• It is the last two points that are exploited during the encoding stage.
Entropy encoding:
It has 4 stages:
1. Vectoring
2. Differential encoding
3. Run-length encoding
4. Huffman encoding.
Vectoring:
• Since the output of the quantization stage is a 2-D matrix of values, in order to apply any
entropy encoding to the set of values in the matrix, we must first represent the values in
the form of a 1-D vector and this operation is known as vectoring.
• In vectoring operation in order to exploit the presence of the large number of zeroes in
the quantization matrix, a zig-zag scan of the matrix is used as shown in the figure
below.
• With this type of scan, the DC coefficient and lower frequency AC coefficients both
horizontal and vertical are scanned first.
• All the high frequency coefficients are in sequential order so making this form of
representation more suitable for compression.
• Two differential encoding schemas are applied in parallel to the values in the vector.
1. Differential encoding to DC-coefficient only
2. Run-length encoding to AC-coefficient
Differential encoding:
• In this stage only the difference in magnitude of the DC coefficient in a quantized block
relatively to the value in the preceding block is encoded.
• In this way number of bits required to encode DC coefficient is reduced significantly.
• Ex: if the sequence of DC coefficients in consecutive quantized blocks-one per block-
were 12,13,11,11,10,…..
• Corresponding difference amount will be, 12, 1,-2, 0,-1…
• The difference values are then encoded in the form (SSS,value)
• Where,
SSS = number of bits needed to encode the value. Value = actual bits that represent
the value.
12 4 1100[ binary
form]
1 1 1
-2 2 01[contemporary
form]
0 0
1 1 0
Run-length encoding:
• The remaining 63 values in the vector are the AC coefficients and, because of the zig-zag
scan, the vector contains long strings of zeros within it.
• To exploit this feature, the AC coefficients are encoded in the form of a string of pairs of
values. Each pair is made up of (skip, value) where
skip = number of zeros in the run and value = next non-zero coefficient.
• Hence the 63 values in the vector would be encoded as: (0,6) (0,7) (0,3) (0,3) (0,3) (0,2)
(0,2) (0,2) (0,2) (0,0)
• Note that the final pair (0,0) indicates the end of the string for this block and that all the
remaining coefficients in the block are zero. Also, that the value field is encoded in the
form SSS/ value.
Huffman encoding :
• Huffman coding is used to encode the output of both the differential and run-length
encoders.
• For the differential-encoded DC coefficients in the block, the bits in the SSS field are not
sent in their unsigned binary form but are sent in a Huffman-encoded form. This is done
so that the bits in the SSS field have the prefix property and this enables the decoder
to determine unambiguously the first SSS field from the received encoded bitstream.
• For each of the run-length encoded AC coefficients in the block. The bits that make up
the skip and SSS fields are treated as a single (composite) symbol and this is then
encoded using either the default table of Huffman codewords or a table of codewords
that is sent with the encoded bitstream.
• This is done so that the strings of encoded composite symbols all have the prefix
property
so that the decoder can interpret the received bitstream on the correct coefficient
boundaries.
• To enable the decoder to discriminate between the skip and SSS fields, each combination
of the two fields is encoded separately and the composite symbol is then replaced by the
equivalent Huffman codeword.
• Because of the use of variable-length codewords in the various parts of the entropy
encoding stage, this is also known as the variable-length coding (VLC) stage.
Frame building:
• In order for the decoder in the remote computer to be able 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, therefore, includes a definition of the
structure of the total bitstream relating to a particular image/picture. This is known as a
frame and its outline structure is shown in Figure below.
Set of Huffman CW’s for the block
• The role of the frame builder is to encapsulate all the information relating to an
encoded image/picture in this format and, the structure of a frame is hierarchical.
• 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/picture.
• The frame header contains a number of fields that include:
1. The overall width and height of the image in pixels
2. The number and type of components that are used to represent the image (CLUT,
R/G/B, Y/Cb/Cr )
3. The digitization format used (4:2:2, 4:2:0 etc.).
• At the second level, a frame consists of a number of components each of which is known
as a scan. These are also preceded by a header which contains fields that include:
1. The identity of the components (R/G/B etc.)
2. The number of bits used to digitize each component
3. The quantization table of values that have been used to encode each component.
• Typically, each scan/component comprises one or more segments each of which can
contain a group of (8 x 8) blocks preceded by a header. This contains the Huffman table
of values that have been used to encode each block in the segment should the default
tables not be used. In this way, each segment can be decoded independently of the
others which overcome the possibility of bit errors propagating and affecting other
segments.
• Hence each complete frame contains all the information necessary to enable the JPEG
decoder to identify each field in a received frame and then perform the corresponding
decoding operation.
JPEG decoding:
• JPEG decoder is made up of a number of stages which are simply the corresponding
decoder sections of those used in the encoder.
• The time to carry out the decoding function is similar to that used to perform the
encoding.
• On receipt of the encoded bitstream the frame decoder first identifies the 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.
• It then starts to pass compressed bitstream to the Huffman decoder which carries out
the corresponding decompression operation using either the default or the preloaded
table of codewords.
• The two decompressed streams containing the DC and AC coefficients of each block are
then passed to the differential and run-length decoders respectively. The resulting
matrix of values is then dequantized using either the default or the preloaded values in
the quantization table.
• Each resulting block of 8 x 8 spatial frequency coefficients is passed in turn to the
inverse DCT which transforms them back into their spatial form using the expression:
cos
P[x,y]= ∑ ∑ C(i) C(j) F[i,j] cos
Compression ratio:
1. JPEG standard is relatively complicated owing to the number of encoding/decoding
stages associated with it, compression ratios in excess of 20:1 can be obtained while
still retaining a good quality output image/picture. This level of compression,
however, applies to pictures whose content is relatively simple - that is, have
relatively few color transitions and
2. For more complicated pictures, compression ratios nearer to 10:1 are more common.
• Finally, as with the GIF, it is also possible to encode and rebuild the image the image in a
progressive way by first sending an outline of the image and progressively adding more
detail to it. This can be achieved in the following ways:
1. Progressive mode:
In this mode, first the DC and low-frequency coefficients of each block are
sent and then the higher-frequency coefficients; 2. Hierarchical mode:
In this mode, the total image is first sent using a low resolution - for
example 320 x 240 - then at a higher resolution such as 640 x 480.