mmc module 3
mmc module 3
MODULE – 3:
Text and Image Compression: Introduction, Compression principles, Text compression,
Imagecompression 8Hours
TEXT BOOK:
REFERENCE BOOKS:
1. “Multimedia Fundamentals: Vol 1 - Media Coding, and Content Processing”, Ralf Steinmetz,
Klara Narstedt, Pearson Education, 2004.
TEXT AND IMAGE COMPRESSION
INTRODUCTION:
In many Multimedia applications a technique known as compression is applied to the
sourceinformation prior to its transmission.
Compression done to achieve 2 things:
1. Reduce the volume of information to be transmitted for text, fax, and images.
2. Reduce the bandwidth required for the transmission of speech, audio, and video.
COMPRESSION PRINCIPLES:
Compression algorithms based on the following compression principles:
1. Source encoders and destination decoders
2. Lossless and lossy compression
3. Entropy encoding
4. Source encoding
Source encoders and destination decoders:
Prior to transmitting the source information relating to a particular multimedia application, a
compression algorithm is applied to it.
In order for the destination to reproduce the original source information or, in some instances,
anearly 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.
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
characteror binary digit.
Here, instead of transmitting source string in the form of independent code words or bits
sourcestring is transmitted in the form of different set of code words which indicates:
Particular character or bit being transmitted
andNumber of characters/bits in the substring
Providing the destination to know the set of code words being used destination simply,
interpretseach code word received and outputs the appropriate number of characters or bits.
Ex.: An application involves transmission of long strings of binary bits that comprise limited
numberof substrings.
Each substring can be assigned a separate code word, total bit string is then transmitted in the
formof the string of code words selected from the code word 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
eitherbinary 0s or 1s.
Instead of transmitting directly, they are sent in the form of a string of code words each
indicatingboth the bit 0 or 1 and the number of strings in the substring.
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
binary0s 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 code word number of bits per code word would be
determined by the largest possible substring.
Statistical encoding:
Applications use a set of code words to transmit the source information.
Ex.: Set of ASCII code words are often used for the transmission of strings of
haracters.Normally, all the code words 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 code words 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
whichagain, will occur more frequently than character Z, and so on.
Statistical encoding exploits this property by using the set of variable length code words, with
the shortest code words used to represent the most frequently occurring symbols.
Use of variable-length code words is not quite as straight-forward. Destination must know the
set of code words being used by the source as in run-length encoding.
When variable-length code words used, in order for the decoding operation to be carried out
correctly. It is necessary to ensure that a shorter code word in the set does not form the
start/beginning of a longer code word otherwise; the decoder will interpret the string on the
wrong code word boundaries.
Prefix property code word 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,
Source encoding:
Uses a particular property of the source information to produce an alternative form of
representation which is:
1. Compressed version of the original form
2. Is more amenable to the application of compression.
Differential encoding:
Used extensively in applications where, the amplitude of a value or signal covers a large range
but Difference in amplitude between successive values/signals is relatively small.
To exploit this property of the source information: A set of smaller code words can be used
each of which indicates only difference in amplitude between the current value/signal being
encoded and the immediately preceding value/signal instead, of using a relatively large code
words to represent the amplitude of each value/signal.
Ex.: If the digitization of analog signal requires say, 12 bits to obtain the required dynamic range
but, the maximum difference in amplitude between successive samples of the signal requires
only 3 bits then, by using only the difference values a saving of 75% on transmission
bandwidth can be saved.
Differential encoding can be loss less or lossy.
Selection of the mode (lossy or lossless) depends on the number of bits used to encode the
difference values.
Transform encoding:
Involves transforming the source information from one form into another form which, lending it
to more readily to the application of compression.
In general, there is no loss of information associated with the transformation operation.
Applications: image and video applications.
Ex.: Digitization of a continuous tone monochromatic image produces a 2-D matrix of pixel
values each of which represents the level of gray in a particular position of the image.
Scenario: Moving from one position in the matrix to the next magnitude of each pixel value can
be varying. So, if a scan is performed across the pixel locations rate of change in magnitude will
vary from zero, if all the pixel values remain the same to a low rate of change if, say one half is
different from the next half through to a high rate of change if each pixel magnitude changes
from one location to thenext as shown in the figure below.
Spatial frequency: It is the rate of change in magnitude as one traverses the matrix.
For any particular image there will be a mix of different spatial frequencies whose amplitudes are
determined by the related changes in magnitude of the pixels.
In practice Human eye is less sensitive to the higher spatial frequency components associated
with an image than, the lower frequency components. If the amplitude of the higher frequency
components falls below a certain amplitude threshold they will not be detected by the eye.
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.
Using above an optimum set of variable length code words (instead of fixed
length) is derived with the shortest code words used to have more frequently
occurring characters.
Resulting set of code words are then used for all subsequent transfers involving
this
type of text.
Dynamic coding(adaptivecoding):
Intended for more general applications type of text transferring may vary from
one transfer to another.
In this case, optimum set of code words also likely to vary from one transfer to
another.
Code word 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.
Code words used change as a transfer takes place in such a way that receiver is
able to dynamically compute the same set of code words that are being used at
each point during a transfer.
Tree construction:
Huffman tree can be constructed from the set of code words, the actual code words,
howeverstart at the root and not the leaf node.
Optimality check for tree (hence for Code words):
1. Listing the resulting weights of all the leaf and branch nodes in the tree starting
withthe smallest weight and proceeding from left to right and from bottom to top.
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 bit stream
mustbe interpreted (decoded) in a bit-oriented way rather than on fixed 7/8 bit
boundaries.
Shorter code word will never form the start of a longer code word which is a prefix
property.
Prefix property: received bit stream can be decoded by carrying out a recursive search
bitby bit until each valid code word is found.
Decoding Algorithm:
Figure below shows the flowchart of a decoding algorithm.
Assumption: Table of code words are available at the receive and also had
correspondingASCII code word.
Received bit stream is held in the variable BIT-STREAM.
Variable CODEWORD - used to hold the bits in each code word - while it is being constructed.
From the flow chart once the code word is identified corresponding ASCII code word
is
written into the variable RECEIVE_BUFFER.
Procedure - repeats until all the bits in the received string have been processed.
Figure below shows example of the decoded string.
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
codewordsrelating to the data being transmitted can be done in 2 ways:
1. Code words relating to the next set of data are sent before the data is transmitted.
Advantage: adaptive compression since, Code words can be changed to
suit the type of data being transmitted.
Disadvantage: overhead of having to send the new set of code words (and
characters corresponding) whenever a new type of data is to be sent.
2. Receiver knows in advance what code words are being used.
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.
Ex.: word processor and bibliography in text books frequency of
occurrence of characters is used to construct the Huffman code tree for
alphabet. If this data is being sent transmitter and receiver automatically
use this set of codewords
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 code word 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 code words:
There are 8 characters –A through H – and hence 3 bits per codeword is sufficient which
is90.7% of the Huffman value.
Using 7-bit ASCII code words:
7 bits per code word 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:
itincrements 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.
If the Sibling Property is about to be violated to update the tree by rearranging
thenodes.
When a swap is necessary, the farthest node with count N is swapped with the
nodewhose count has just been increased to N+1. Note that if the node with
count
N is not a leafnode- it is the root of a subtree the entire subtree will go with it during
the swap.
The encoder and decoder must use exactly the same Initial_code and update_tree
routines.
Ex: AADCCDD
To improve the implementation of the algorithm, we adopt an additional rule: if any
character/symbol is to be sent the first time, it must be preceded by a special symbol
NEW. The initial code for NEW is 0. The count for NEW is always kept as 0.
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.
Regulation – 2017(CBCS MULTIMEDIA COMMUNICATION –
Regulation – 2017(CBCS MULTIMEDIA COMMUNICATION –
Regulation – 2017(CBCS MULTIMEDIA COMMUNICATION –
MULTIMEDIA COMMUNICATION –
MULTIMEDIA COMMUNICATION –
MULTIMEDIA COMMUNICATION –
MULTIMEDIA COMMUNICATION –
MULTIMEDIA COMMUNICATION –
Arithmetic Coding:
Huffman coding achieves the Shannon value only if the character/symbol probabilities
areall integer powers of 1/2.
In contrast, the code word produced using arithmetic coding always achieve the
Shannonvalue.
It yields a Single Code word for each encoded string of characters however Huffman
coding yields a single code word for each encoded characters in a string.
Arithmetic coding, however, is more complicated than Huffman coding.
Algorithm:
BEGIN:
MULTIMEDIA COMMUNICATION –
A message is represented by a half-open interval [a,b) here a & b are real numbers
between0 & 1.
Initially the interval is [0,1). When the message becomes longer, the length of the
interval shortens and the number of bits needed to represent the interval increases.
At the end of each character string making up a message, a known character is sent
which, in this example, is a period (.) . When this is decoded at the receiving side, the
decoder interprets this as the end of the string/message.
To illustrate how the coding operation takes place, consider the transmission of a
message comprising a string of characters with probabilities
Calculations:
High=low+(range × range_high(symbol))
Encoded version of the character string went. Is a single codeword in the range
MULTIMEDIA COMMUNICATION –
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.’
MULTIMEDIA COMMUNICATION –
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 code word = 0.81611.
Seeing the above output decoder interprets 1st character as ‘w’ since it is in the range of
0.8to 0.9.
It then expands the above interval further and determines that the 2nd character is ‘e’
as0.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
thenumber of character in the string to be encoded.
Maximum number of characters in a string is determined by the precision with
whichfloating 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
blockof floating-point number each in a known format.
Lempel-Ziv coding:
Advantage:
The Lempel-Ziv (LZ) compression algorithm, instead of using single characters
asthe basis of the coding operation, uses strings of characters.
Ex., for the compression of text, a table containing all the possible
character strings of words that occur in the text to be transferred is held
by both the encoder and decoder.
Operation:
As each word occurs in the text, instead of sending the word as a set of individual
ASCII code words, 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.
Thus the table is used as a dictionary and the LZ algorithm is known as dictionary-based
compression algorithm.
Scenario:
Most word processing packages have a dictionary associated with them which
MULTIMEDIA COMMUNICATION –
is
MULTIMEDIA COMMUNICATION –
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:
It can be relatively inefficient if the text to be transmitted comprises only a small
subset of the words stored in the dictionary.
Solution for limitation:
Hence a variation of the LZ algorithm has been developed which allows the
dictionary to be built up dynamically by the encoder and decoder as the
compressed text is being transferred. In this way, the size of the dictionary is
often a better match to the number of different words in the text being
transmitted than if a standard dictionary was used.
Lempel-Ziv-Welsh coding:
Principle of operation:
Here encoder and decoder will build the contents of the dictionary dynamically
asthe text is being transferred.
Initially, the dictionary held by both the encoder and decoder contains only
thecharacter set example ASCII that has been used to create the text.
The remaining entries in the dictionary are then built up dynamically by both
theencoder 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:
MULTIMEDIA COMMUNICATION –
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 containempty 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.
This requires an index/codeword length of 8 bits and the dictionary would provide
MULTIMEDIA COMMUNICATION –
space for the 128 characters in the character set and a further 128 locations for
words that occur in the text.
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
encoderuses 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.
The procedure is shown in diagrammatic form in figure 3.8(b).
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.
Algorithm (Compression):
BEGIN
s = next input character; while not EOF
{ c = next input character;
if s + c exists in the dictionary s = s
+ c;else
{ output the code for s;
add string s + c to the dictionary with a new code; s = c;
}
}
output the code for s; END
Problem:
1. Compress the following string “ABABBABCABABBA” using LZW Algorithm.
Solution:
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
MULTIMEDIA COMMUNICATION –
2 B
3 C
Now if the input string is “ABABBABCABABBA”, the LZW compression algorithm works as follows:
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
besent (compression ratio = 14/9 = 1.56).
MULTIMEDIA COMMUNICATION –
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.
Theinitial 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
MULTIMEDIA COMMUNICATION –
ABB 1 A 11 ABBA
A EOF
Code String
1 A
2 B
3 C
4 E
Solution: Now if the input string is “ABCBCABCEAB”, the LZW compression algorithm works
asfollows:
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
MULTIMEDIA COMMUNICATION –
MULTIMEDIA COMMUNICATION –
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
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
MULTIMEDIA COMMUNICATION –
MULTIMEDIA COMMUNICATION –
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.
1 M
2 Y
3 E
4 O
NIL 1 M
M 2 Y 5 MY
Y 1 M 6 YM
MULTIMEDIA COMMUNICATION –
M 3 E 7 ME
E 5 MY 8 EM
MY 1 M 9 MM
M 4 O 10 MO
O EOF
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 bit and color digitized pictures.
MULTIMEDIA COMMUNICATION –
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
MULTIMEDIA COMMUNICATION –
of
MULTIMEDIA COMMUNICATION –
entries in the table is allowed to increase incrementally by extending the length of the
indexby 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 isbuilt 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.
MULTIMEDIA COMMUNICATION –
JPEG:
JPEG is an acronomy for Joint Photographic Expert Group.
It is the widely adapted standards relating to the compression of digitized pictures.
There are 5 main stages they are:
1. Image/block preparation
2. Forward DCT
3. Quantization
4. Entropy Encoding
5. Frame Building
Developed by ISO and ITU-T for United Nation
Figure below shows Encoder schematic
MULTIMEDIA COMMUNICATION –
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 of8-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
theR, 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.
Each is known as block and is fed sequentially to the DCT which transforms each
blockseparately 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
forthe 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
fromeach 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:
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.
MULTIMEDIA COMMUNICATION –
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
belowtogether with a set of DCT coefficients and their corresponding quantizedvalues.
MULTIMEDIA COMMUNICATION –
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
thenearest integer value.
2. The threshold values used, in general, increase in magnitude with increasing
spatialfrequency.
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
theform 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.
MULTIMEDIA COMMUNICATION –
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
blockrelatively 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-
were12,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
thevalue.
MULTIMEDIA COMMUNICATION –
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
-zagscan, 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 ofvalues. 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
MULTIMEDIA COMMUNICATION –
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.
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
MULTIMEDIA COMMUNICATION –
(CLUT,
MULTIMEDIA COMMUNICATION –
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 asa 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 bit stream 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:
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.