0% found this document useful (0 votes)
8 views

Data Compression

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Data Compression

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Fundamentals of Multimedia

2nd Edition 2014


Ze-Nian Li
Mark S. Drew
Jiangchuan Liu

Part II:
Multimedia Data Compression
Chapter 7,8,9,10:
Lossless Compression Algorithms
1
 In this Part we examine the role played in multimedia by data
compression, perhaps the most important enabling
technology that makes modern multimedia systems possible.

 So much data exist, in archives, via streaming, and elsewhere,


that it has become critical to compress this information.

 We start off in Chap. 7 looking at lossless data


compression i.e., involving no distortion of the original
signal once it is decompressed or reconstituted.

2
7.1 Introduction
 Compression: the process of coding that will effectively
reduce the total number of bits needed to represent
certain information.
 Figure 7.1 depicts a general data compression scheme, in which
compression is performed by an encoder and decompression
is performed by a decoder.

Fig. 7.1: A General Data Compression Scheme.

We call the output of the encoder codes or codewords. The intermediate medium could either be
data storage or a communication/computer network.
3
7.1 Introduction
 If the compression and decompression processes induce no
information loss, then the compression scheme is lossless;
otherwise, it is lossy.
 Compression ratio:

(7.1) 

 B0 – number of bits before compression


 B1 – number of bits after compression
 In general, we would desire any codec (encoder/decoder
scheme) to have a compression ratio much larger than 1.0.
 The higher the compression ratio, the better the lossless
compression scheme, as long as it is computationally feasible.
4
7.2 Basics of Information Theory
 According to the famous scientist Shannon, the entropy
η of an information source with alphabet S = {s1, s2, . . . ,
sn} is:
n
1
  H ( S )   pi log 2
i 1 pi  (7.2)
n
  pi log 2 pi  (7.3)
i 1

 pi – probability that symbol si will occur in S.


1

log
– indicates the amount of information ( self-
2 pi
information as defined by Shannon) contained in si,
which corresponds to the number of bits needed to
encode si.
5
7.2 Basics of Information Theory
 What is entropy? In science, is a measure of the number of
specific ways in which a system may be arranged, commonly
understood as a measure of the disorder of a system.The
more the entropy, the more the disorder.

 As an example, if the information source S is a gray-level


digital image, each si is a gray-level intensity ranging from 0 to
(2k − 1), where k is the number of bits used to represent each
pixel in an uncompressed image.
 We need to find the entropy of this image; which the
number of bits to represent the image after
compression. -> next slide

6
Distribution of Gray-Level Intensities
The image histogram is a way of calculating the probability pi of
having pixels with gray-level intensity i in the image.

 Fig. 7.2 Histograms for Two Gray-level Images.

• Fig. 7.2(a) shows the histogram of an image with uniform distribution


of gray-level intensities, i.e., ∀i pi = 1/256. Hence, the entropy of this
image is:
 (7.4)

7
Distribution of Gray-Level Intensities

 Fig. 7.2 Histograms for Two Gray-level Images.

• Figure 7.2b shows the histogram of another image, in which 1/3 of


the pixels are rather dark and 2/3 of them are rather bright. The
entropy of this image is

In general, the entropy is greater when the probability distribution is


flat and smaller when it is more peaked.
8
Distribution of Gray-Level Intensities
 It is interesting to observe that in the above uniform-
distribution example (fig. 7-2 (a)) we found that η = 8, the
minimum average number of bits to represent each gray-level
intensity is at least 8. No compression is possible for this
image.
 In the context of imaging, this will correspond to the “worst
case,” where neighboring pixel values have no similarity.

9
7.3 Run-Length Coding
• RLC is one of the simplest forms of data compression.
 The basic idea is that if the information source has the property that
symbols tend to form continuous groups, then such symbol and the
length of the group can be coded.
 Consider a screen containing plain black text on a solid white
background.
 There will be many long runs of white pixels in the blank space, and
many short runs of black pixels within the text. Let us take a
hypothetical single scan line, with B representing a black pixel and W
representing white:
WWWWWBWWWWBBBWWWWWWBWWW
 If we apply the run-length encoding (RLE) data compression
algorithm to the above hypothetical scan line, we get the following:
5W1B4W3B6W1B3W
 The run-length code represents the original 23 characters in only 14.

10
7.4 Variable-Length Coding
 Variable-length coding (VLC) is one of the best-known
entropy coding methods

 Here, we will study the Shannon–Fano algorithm, Huffman


coding.

11
7.4.1 Shannon–Fano Algorithm
 To illustrate the algorithm, let us suppose the symbols to be
coded are the characters in the word HELLO.
 The frequency count of the symbols is
Symbol H E L O
Count 1 1 2 1
 The encoding steps of the Shannon–Fano algorithm can be
presented in the following top-down manner:
 1. Sort the symbols according to the frequency count of their
occurrences.
 2. Recursively divide the symbols into two parts, each with
approximately the same number of counts, until all parts
contain only one symbol.

12
7.4.1 Shannon–Fano Algorithm
 A natural way of implementing the above procedure is to
build a binary tree.
 As a convention, let us assign bit 0 to its left branches and 1
to the right branches.
 Initially, the symbols are sorted as LHEO.
 As Fig. 7.3 shows, the first division yields two parts: L with a
count of 2, denoted as L:(2); and H, E and O with a total
count of 3, denoted as H, E, O:(3).
 The second division yields H:(1) and E, O:(2).
 The last division is E:(1) and O:(1).

13
7.4.1 Shannon–Fano Algorithm

Fig. 7.3: Coding Tree for HELLO by Shannon-Fano. 14


Table 7.1: Result of Performing Shannon-Fano on HELLO

Symbol Count Log2 1 Code # of bits used


pi
L 2 1.32 0 2
H 1 2.32 10 2
E 1 2.32 110 3
O 1 2.32 111 3
TOTAL # of bits: 10

15
16
 Fig. 7.4 Another coding tree for HELLO by Shannon-
Fano.

17
 Table 7.2: Another Result of Performing Shannon-Fano
 on HELLO (see Fig. 7.4)

Symbol Count Log2 1 Code # of bits used


pi
L 2 1.32 00 4
H 1 2.32 01 2
E 1 2.32 10 2
O 1 2.32 11 2
TOTAL # of bits: 10

18
7.4.1 Shannon–Fano Algorithm
 The Shannon–Fano algorithm delivers satisfactory coding results
for data compression, but it was soon outperformed and
overtaken by the Huffman coding method.
 First presented by Huffman in a 1952 paper, this method
attracted an overwhelming amount of research and has
been adopted in many important and/or commercial
applications, such as fax machines, JPEG, and MPEG.
 In contradistinction to Shannon–Fano, which is top-down,
the encoding steps of the Huffman algorithm are described
in the following bottom-up manner. Let us use the same
example word, HELLO.
 A similar binary coding tree will be used as above, in which
the left branches are coded 0 and right branches 1. A simple
list data structure is also used.
19
7.4.1 Shannon–Fano Algorithm
 Algorithm 7.1 (Huffman Coding).
 1.Initialization: put all symbols on the list sorted according
to their frequency counts.
 2. Repeat until the list has only one symbol left.
 (a) From the list, pick two symbols with the lowest
frequency counts. Form a Huffman subtree that has these
two symbols as child nodes and create a parent node for
them.
 (b) Assign the sum of the children’s frequency counts to the
parent and insert it in to the list, such that the order is
maintained.
 (c) Delete the children from the list.
 3. Assign a code word for each leaf based on the path from
the root. 20
7.4.1 Shannon–Fano Algorithm

21
7.4.1 Shannon–Fano Algorithm
 In Fig. 7.5, new symbols P1, P2, P3 are created to refer to the
parent nodes in the Huffman coding tree. The contents in
the list are illustrated below:
 After initialization: L H E O
 After iteration (a): LP1H
 After iteration (b): LP2
 After iteration (c): P3

22
7.4.1 Shannon–Fano Algorithm
 For this simple example, the Huffman algorithm apparently
generated the same coding result as one of the Shannon–
Fano results we have shown, although the results are usually
better.
 The average number of bits used to code each character is
also 2, (i.e., (1 + 1 + 2 + 3 + 3)/5 = 2).

23
7.5 Dictionary-Based Coding

 The Lempel-Ziv-Welch (LZW) algorithm employs an


adaptive, dictionary-based compression technique.

 LZW proceeds by placing longer and longer repeated entries


into a dictionary, then emitting (sending) the code for an
element rather than the string itself, if the element has already
been placed in the dictionary.

 LZW is used in many applications, such as UNIX compress,


GIF for images, WinZip, and others.

24
7.5 Dictionary-Based Coding

 See Examples of Coding and Decoding from here:


 [1] https://www.youtube.com/watch?v=rZ-
JRCPv_O8&t=196s

 [2] https://www.youtube.com/watch?v=MQM_DsX-LBI

25
End of Chapter 7

26
Fundamentals of Multimedia

2nd Edition 2014


Ze-Nian Li
Mark S. Drew
Jiangchuan Liu

Part II:
Multimedia Data Compression
Chapter 8 :
Lossy Compression Algorithms
27
8.1 Introduction
 The compression ratio for image data using lossless
compression techniques (e.g., Huffman Coding, Arithmetic
Coding, LZW) is low when the image histogram is
relatively flat.

 For image compression in multimedia applications, where


a higher compression ratio is required, lossy methods are
usually adopted.

 In lossy compression, the compressed image is usually not


the same as the original image but is meant to form a
close approximation to the original image perceptually.

28
8.2 DistortionMeasures
 To quantitatively describe how close the approximation is
to the original data, some form of distortion measure is
required.
 A distortion measure is a mathematical quantity that
specifies how close an approximation is to its original,
using some distortion criteria.
 When looking at compressed data, it is natural to think of
the distortion in terms of the numerical difference
between the original data and the reconstructed data.

29
8.2 DistortionMeasures
 Of the many numerical distortion measures that have
been defined is the the mean square error (MSE) .
 If we are interested in the average pixel difference, the
mean square error (MSE) 𝜎 2 is often used. It is defined as

 where xn, yn, and N are the input data sequence,


reconstructed data sequence, and length of the data
sequence, respectively.

30
End of Chapter 8

31
Fundamentals of Multimedia

2nd Edition 2014


Ze-Nian Li
Mark S. Drew
Jiangchuan Liu

Part II:
Multimedia Data Compression
Chapter 9:
Image Compression Standards
32
 Recent years have seen an explosion in the availability of
digital images, because of the increase in numbers of
digital imaging devices such as smart phones, webcams,
digital cameras, and scanners.

 The need to efficiently process and store images in digital


form has motivated the development of many image
compression standards for various applications and needs.

 In general, standards have greater longevity than


particular programs or devices and therefore warrant
careful study.

33
9.1 image compression standard
 Some current standards are:
 JPEG
 JPEG2000 standard
 JPEG-LS Standard
 JBIG Standard
 JBIG2 Standard

34
End of Chapter 9

35
Fundamentals of Multimedia

2nd Edition 2014


Ze-Nian Li
Mark S. Drew
Jiangchuan Liu

Part II:
Multimedia Data Compression
Chapter 10 :
Basic Video Compression Techniques
36
 As discussed in Chap. 7, the volume of uncompressed
video data could be extremely large.

 Even a modest CIF video with a picture resolution of only


352 × 288, if uncompressed, would carry more than 35
Mbps.

 In HDTV, the bitrate could easily exceed 1 Gbps.


 In telecommunications and computing, bit rate (sometimes
written bitrate or as a variable R) is the number of bits that are
conveyed or processed per unit of time.

 This poses challenges and problems for storage and


network communications.
37
 H.261 and H.263— are two video compression standards
aimed mostly at videoconferencing.

38
10.1 Introduction to Video Compression

 In the field of video compression a video frame is


compressed using different algorithms with different
advantages and disadvantages, centered mainly around
amount of data compression. These different algorithms
for video frames are called picture types or frame
types. The three major picture types used in the different
video algorithms are I, P and B. They are different in their
characteristics.

39
10.1 Introduction to Video Compression

Three types of pictures (or frames) are used in video compression: I, P, and B frames.

An I-frame (Intra-coded picture), a complete image, like a JPG or BMP image file.

P and B frames hold only part of the image information (the part that changes
between frames), so they need less space in the output file than an I-frame.

A P-frame (Predicted picture) holds only the changes in the image from the
previous frame. For example, in a scene where a car moves across a stationary
background, only the car's movements need to be encoded. The encoder does not
need to store the unchanging background pixels in the P-frame, thus saving space.
P-frames are also known as delta-frames.

A B-frame (Bidirectional predicted picture) saves even more space by using


differences between the current frame and both the preceding and following frames
to specify its content.
40
10.1 Introduction to Video Compression
 As we mentioned, a video consists of a time-ordered
sequence of frames—images. An obvious solution to
video compression would be predictive coding based on
previous frames.
 For example, suppose we simply created a predictor such
that the prediction equals the previous frame.
 However, it turns out that at acceptable cost, we can do
even better by searching for just the right parts of the
image to subtract from the previous frame.

41
End of Chapter 10

42
MPEG-1
MPEG: Moving Pictures Experts Group, established in 1988 for the
development of digital video.

43
Group Worksheet

44
END

45
Kingdom of Saudi Arabia ‫المملكة العربية السعودية‬
Ministry of Education ‫وزارة التعليم‬
Umm AlQura University ‫جامعة أم القرى‬
Adam University College ‫الكلية الجامعية أضم‬
Computer Science Department ‫قسم الحاسب اآللي‬

This Summary is an Online Content from this Book:


Ze-Nian Li and Mark S Drew, Fundamentals of Multimedia, 1/e, Prentice-Hall, 2004

It is edited for
Multimedia Systems Course 6803316-3
by:
T.Mariah Sami Khayat
Teacher Assistant @ Adam University College
For Contacting:
[email protected]
46

You might also like