Application of Compression

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

A Survey of Data Compression Algorithms and

their Applications
Mohammad Hosseini
Network Systems Lab
School of Computing Science
Simon Fraser University, BC, Canada
Email: mohammad [email protected]

Abstract—Today, with the growing demands of infor- enumerate some recent issues and approaches regarding
mation storage and data transfer, data compression is data compression, like energy consumption.
becoming increasingly important. Data Compression is
a technique which is used to decrease the size of data. II. DATA C OMPRESSION A LGORITHMS : L OSSY
This is very useful when some huge files have to be AND L OSSLESS COMPRESSION
transferred over networks or being stored on a data Basically, we have two types of data compression al-
storage device and the size is more than the capacity of gorithms. Lossless algorithms, which can reconstruct the
the data storage or would consume so much bandwidth
original message exactly from the compressed message,
for transmission in a network. With the advent of the
Internet and mobile devices with limited resources, data and lossy algorithms, which can only reconstruct an ap-
compression has gained even more importance. It can proximation of the original message. Lossless algorithms
be effectively used to save both storage and bandwidth, are typically used for text, and lossy compression algo-
thus to decrease download duration. Data compression can rithms, on the other hand, remove unnecessary data per-
be achieved by a host of techniques. During this survey, manently and so the original data cannot be completely
I’m going to thoroughly discuss some of important data regenerated. This is used for image, sound and video
compression algorithms, their performance evaluation, and compression since it can cause significant reduction in
their major applications along with today’s issues and
file size with no significant quality reduction.
recent research approaches.
III. L OSSLESS DATA C OMPRESSION
I. I NTRODUCTION A. Huffman Algorithm
Data compression is one of the enabling technologies Huffman coding algorithm was first developed by
for multimedia applications. It would not be practical David Huffman as part of a class assignment! The class
to put images, audio and video on websites if do not was the first ever in the area of information theory and
use data compression algorithms. Mobile phones would was taught by Robert Fano at MIT. The codes generated
not be able to provide communication clearly without by this algorithm are called Huffman codes. These codes
data compression. With data compression techniques, we are prefix codes and are optimum for a given model (set
can reduce the consumption of resources, such as hard of probabilities). The Huffman procedure is based on two
disk space or transmission bandwidth. In this survey, observations regarding optimum prefix codes:
first we introduce the concept of lossy and lossless 1) In an optimum code, symbols that occur more fre-
data compression techniques, and will thoroughly discuss quently (have a higher probability of occurrence)
some of their major algorithms. Then we pick two of the will have shorter codewords than symbols that
mostly used compression algorithms, implement them occur less frequently.
and compare their compression ratio as a performance 2) In an optimum code, the two symbols that occur
factor. Then in the third part, we discuss some of least frequently will have the same length.
the most significant applications of data compression It is easy to see that the first observation is correct.
algorithms in multimedia compression, JPEG and MPEG If symbols that occur more often had codewords that
coding algorithms. Finally in the last section we would were longer than the codewords for symbols with less
Fig. 1. Probabilities of alphabets in the example word

number of occurrences, the average number of bits per


symbol would be larger comparing with the reverse
case. Therefore, a code that assigns longer codewords to Fig. 2. Steps of applying huffman coding on HELLO
symbols that occur more frequently cannot be optimum.
[1] TABLE I
Huffman coding is used as a variable length coding. H UFFMAN ALGORITHM CODES FOR THE EXAMPLE
Characters in files are stored in ASCII codes, each
Symbol Count Code Number of bits
taking up exactly 1 byte. This is a fixed-length code.
L 2 0 1*2
The Huffman algorithm assigns codes to the characters H 1 10 2
depending on the number of repentance occur in the E 1 110 3
file which gives the shortest code to the most frequently O 1 1110 3
occurring character. This results in a variable length
code. Huffman codes are uniquely decodable.
sion depending on the different types of applications.
Algorithm: The algorithm is as follows: These versions mainly differ in the method of creating
1) Select two symbols with the least probability form the Huffman tree.
a binary tree. The left child has larger probability Lemma: The Huffman coding is a ”minimum-
than the right child. redundancy code” algorithm and it has been proven
2) The parent node has probability of the sum of the that it is an optimal code for a set of data with given
two symbols. The two child symbols are removed probability. It has the following properties: The two
from the entries and replaced by their parent. symbols with least probability are located at leaf of the
3) Recursively repeat step 1 until all symbols have same parent and their codes have same length. Symbol
been put in the binary coding tree. [2] with higher probability has shorter code (fewer bits) than
symbols with lower probability. The average length of
Example: Consider the word HELLO. Now we use code agrees with the following equation: [3]
P
this text in order to show how the algorithm works. n ≤ averagelength < n + 1 : n = Pi log2 (1/Pi )
Fig. 1 shows the probability of occurrence of a single
alphabet. Now based on the algorithms, we go ahead Adaptive Huffman Coding
with these alphabets probabilities. Fig. 2 represents the In practical uses, we don’t have the statistical infor-
steps towards encoding the example word based of mation in prior. Adaptive Huffman method updates the
Huffman coding. statistical information while receiving new data. When
Table I shows the results after applying Huffman the probability of a symbol increases (decreases), the
coding on the example. As shown in the table, the total code of that symbol would be updated in order to make
number of bits is 10, the average bit number of each it shorter (longer).
symbol is 10/5 = 2 bit/symbol. In the adaptive Huffman coding procedure, none of
transmitter and receiver has information about the statis-
Effectiveness: The Huffman algorithm is quite effec- tics of the source sequence at the start of transmission.
tive for compression in almost all file formats. Different The tree in the transmitter and the receiver consists of a
versions of this algorithm can be designed for compres- single node which actually stands for all symbols not
TABLE II
RESULTS OF USINGT UNSTALL CODING

sequence code
B 000
C 001
AB 010
AC 011
AAA 100
AAB 101
AAC 110

bits for alphabets that occur less frequently. The


Tunstall code is an important exception. The lengths
of Tunstall Codes are equal, but the codes represent
variable length of symbols. The main advantage of this
method is that there is no accumulated error due to
variable-length code. Instead of assigning fewer bits
Fig. 3. Adaptive Huffman Coding after processing [a a r d v a r k] code to higher probability symbol, Tunstall coding
concatenate symbol having highest probability with
every other symbol together to form new strings
yet transmitted (NYT) and has a weight of zero. As replacing the original symbol. After K times iterations,
we go ahead with transmission, nodes corresponding to the number of symbols becomes N+K(N-1). For an
symbols transmitted will be added to the tree, and the n-bit coding, N + K(N − 1)2n . [?] Here we provide
tree would be reconfigured using an update procedure. an example: We assume having a data set with the
Before the beginning of transmission, a fixed code for alphabets A, B, and C and we assume the probability
each symbol is agreed between transmitter and receiver. distributions are: P(A)=0.6, P(B)=0.3, P(C)=0.1 .
[4] The algorithm goes this way: Select a conventional Alphabet A has the highest probability, so we find all
used code such as ASCII as an initial code. Whenever two-alphabet strings with prefix A (AA, AB, and AC) to
a symbol input has been occurred, the encoder checks replace A. As figure 8 shows, after two runs, there are
the Huffman encoding tree. If there are any probabilities 7 entries 2n . The final 3-bit code is shown in table II. [3]
which are larger than their parents’ generation, swap
them, until all the probability of each entry is smaller Applications of Huffman coding:
than its parents’ generation. Huffman coding and its different variations have gained
As an example, assume we are encoding the message so much importance due to wide variety of applications.
[a a r d v a r k], where our alphabet consists of the 26 Arithmetic coding (which I will discuss later in this
lower-case letters of the English alphabet. Fig. 3 shows survey) can be viewed as a generalization of Huffman
the coding process for our example. coding, in the sense that they produce the same output
when every symbol has a probability of the form 1/2k;
Besides above methods, in some particular conditions, in particular this algorithm offers significantly better
there are other effective methods. For instance Tunstall compression for small alphabet sizes. However Huffman
coding is a popular method which we would discuss in coding algorithm remains in wide use because of its
the followings. simplicity and high speed. Intuitively, arithmetic cod-
ing can offer better compression than Huffman coding
Tunstall Coding: because its ”code words” can have bit lengths which
Most of the variable-length coding algorithms that we are not necessarily integers, while we see code words in
look at in this survey encode letters from the source Huffman coding can only have an integer number of bits.
alphabet using codewords with varying numbers of Therefore, there is an inefficiency in Huffman coding
bits: codewords with fewer bits for alphabets that where a code word of length k only optimally matches
occur more frequently and codewords with more a symbol of probability 1/2k and other probabilities are
not represented as optimally; wihle the code word length is not useful with files which don’t have many runs as
in arithmetic coding can be made to exactly match the it could greatly increase the file size.
true probability of the symbol. [4] As an example, consider a plain black text on a
Huffman coding today is often used as a ”back- solid white background. There will be many long runs
end” to some other compression methods. DEFLATE of white pixels in the blank space, and many short
(PKZIP’s algorithm) and multimedia codecs such as runs of black pixels within the text. Let’s consider a
JPEG (which we would discuss later in this survey) and single line of pixels, with B representing a black pixel
MP3 format have a model and quantization followed by and W representing white: WWWWWBWWWWWWBBB-
Huffman coding. Image compression, Text compression WWWWWBWWWWW
and Audio compression are the major applications of If we apply the run-length coding (RLE) data com-
Huffman coding: pression algorithm to the above pixel line, we get the
• Image compression: following sequence: 5W1B5W3B5W1B5W This is to be
For instance, a simple application of Huffman coding interpreted as five Ws, one B, five Ws and so on.
to image compression would be to generate a Huffman The run-length code represents the original 25 char-
code for the set of values that any pixel may take. For acters in form of only 14 characters. Of course, the
monochrome images, this set usually consists of integers actual format used for the storage of images is generally
from 0 to 255. binary rather than ASCII characters like this, but the
• Text compression:
principle remains the same. Even binary data files can be
compressed with this method; file format specifications
Text compression seems natural for Huffman coding.
often cause repeated bytes in files. However, some newer
In text, we have a discrete alphabet that has relatively
compression methods use a generalization of RLE that
stationary probabilities. For example, the probability
can take advantage of runs of strings of characters
model for a particular novel will not differ significantly
instead of single characters (such as BWWBWWBWW).
from the probability model for another novel. Similarly,
And regarding its applications, since run-length en-
the probability model for a set of Java codes also is not
coding performs lossless data compression, it is well
going to be much different than the probability model
suited to palette-based images, like textures. It is not
for a different set of Java codes.
usually applied on realistic images such as photographs.
• Audio compression:
Although JPEG (which will be discussed later in this
Another class of data that is very suitable for compres- survey) uses it quite effectively on the coefficients that
sion is CD-quality audio data. The audio signal for each remain after transforming and quantizing image blocks.
stereo channel is sampled at 44.1 kHz, and each sample [4]
is represented by 16 bits. This means that the amount Run-length encoding is used in fax machines. It is
of data stored on a single CD is so much. If we want relatively efficient because most faxed documents have
to transmit this data, the amount of channel capacity so much white space, with occasional interruptions of
required would be significant. Compression woudl be black.
definitely useful in this case.

B. Run-Length Coding C. Lempel-Ziv Algorithm


Consider the idea say that once a pixel takes on a The Lempel-Ziv algorithm which is a dictionary-based
particular color (black or white), it is highly likely that coding algorithm (unlike the previous coding algorithms
the following pixels will also be of the same color. So, which were based on probability coding) is the most
rather than code the color of each pixel separately, we preferred method for lossless file compression. This is
can simply code the length of the runs of each color. mainly due to its adaptability to different file formats. It
Run-length encoding (RLE) is a very simple form of searches for frequently occurring phrases, say combina-
data compression in which sequences of data (which is tions of symbols and replaces them by a single symbol.
called a run, repeating string of characters) are stored It maintains a dictionary of these phrases and appends it
in two parts: a single data value and the count, rather to the final file. The length of the dictionary is fixed to a
than as the original run. This is most useful on data that certain value. For small files, the length of the dictionary
contains many such runs: for example, simple graphic may exceed the length of the original file, but for large
images such as icons, line drawings, and animations. It files, this method is very effective. [5]
TABLE III
The two main variants of the algorithm were described RESULTS OF USING T UNSTALL CODING
by Ziv and Lempel in two separate papers in 1977 and
1978, and are often refered to as LZ77 and LZ78. The Symbol Next symbol Output Code String
algorithms differ in how far back they search and how A B 1 4 AB
they find matches. The LZ77 algorithm is based on the B A 2 5 BA
idea of a sliding window. The algorithm only looks for AB B 4 6 ABB
B A
matches in a window within a fixed distance back from
BA B 5 7 BAB
the current position. Gzip, ZIP, and V.42bis (a standard
B C 2 8 BC
modem protocol) are all based on LZ77. The LZ78 C A 3 9 CA
algorithm is based on a more conservative approach to A B
adding strings to the dictionary. [4] AB A 4 10 ABA
Lempel-Ziv-Welch (LZW) is the mostly used A B
Lempel-Ziv algorithm. Lempel-Ziv-Welch compression AB B
algorithm is proposed by Terry Welch in 1984. It is ABB A 6 11 ABBA
improved base on the LZ77 and L78 compression A EOF 1
algorithm. The encoder builds an adaptive dictionary
to represent the variable-length strings Without any
prior probability information. The decoder also builds Since the publication of Terry Welchs article, there
the same dictionary in encoder according to received has been a steadily increasing number of applications
code dynamically. In text data, some symbols/characters that use some variant of the LZ algorithm. Among the
occur together frequently. The encoder can memorize LZ variants, the most popular is the LZW algorithm.
these symbols and represent them in one code. [6] A However LZW algorithm was initially the mostly used
typical LZW code is 12-bits length (4096 codes). The algorithm, patent concerns has led to increasing use
first 256 (0 255) entries are ASCII codes, to represent of the LZ algorithm. The most popular implementation
individual character. The other 3840 (256 4095) codes of the LZ algorithm is the deflate algorithm initially
are defined by encoder to represent variable-length designed by Phil Katz. Deflate is a lossless data com-
strings. Now LZW is applied in GIF images, UNIX pression algorithm that uses a combination of the LZ
compress, and others. [2] The algorithm goes this way: algorithm and Huffman coding. So as we discussed in
the Huffman coding section, it is considered a variant
1) Initialize the dictionary. of both algorithms. It is part of the popular zlib library
2) Combine symbols of the input data together developed by Jean-loup Gailly and Mark Adler. [7] Jean-
sequentially into buffer until the longest loup Gailly also used deflate in the widely used gzip
string/symbol can be found in the dictionary. algorithm. The deflate algorithm is also used in PNG
3) Send the code representing in the buffer. image format which we will also describe below. [4]
4) Save the string in the buffer combining with the Here we enumerate some of major applications of LZ
next symbol in the next empty code into the algorithms:
dictionary.
5) Clear the buffer, then repeat Steps 2 to 5 until the • File CompressionUNIX compress:
end of total data. The UNIX compress command is one of the earliest
applications of LZW. The size of the dictionary is
An example of LZW is shown in table III. [4] The adaptive. We start with a dictionary of size 512. This
input string is ABABBABCABABBA and the initial means that the transmitted codewords have 9 bits in
code is 1, 2, and 3 to representing A, B, and C. length. Once the dictionary has filled up, the size of the
The encoded string is ”124523461”. The data is dictionary is doubled to 1024 entries. The codewords
compressed from 14 characters to 9 characters. The transmitted at this point have 10 bits. The size of the
compression ratio is thus 14/9 = 1.56. If we also take dictionary is progressively doubled as it fills up. In
into account the bit number, a typical 12-bits LZW for this way, during the earlier part of the coding process
example, the ratio becomes (814)/( 129)=1.04. when the strings in the dictionary are not very long, the
codewords used to encode them also have fewer bits. The
Applications of LZ coding: maximum size of the codeword, bmax, can be set by the
TABLE IV
user to between 9 and 16, with 16 bits being the default. USING ARITHMETIC CODING
Once the dictionary contains 2bmax entries, compress
becomes a static dictionary coding technique. At this symbol probability interval
point the algorithm monitors the compression ratio. If the A 0.2 [0, 0.2)
compression ratio falls below a threshold, the dictionary B 0.1 [0.2, 0.3)
would be flushed, and the dictionary building process C 0.2 [0.3, 0.5)
D 0.05 [0.5, 0.55)
is restarted. This way, the dictionary always reflects the
E 0.3 [0.55, 0.85)
local characteristics of the source.
F 0.05 [0.85, 0.9)
• Image Compression-GIF format: @ 0.1 [0.9, 1)
The Graphics Interchange Format (GIF) was devel-
oped by Compuserve Information Service to encode
graphical images. It is another implementation of the
LZW algorithm and is very similar to the compress
command in Unix, as we mentioned in the previous
application.
• Image CompressionPNG format:
PNG standard is one of the first standards to be de-
veloped over the Internet. The motivation for its devel-
opment was an announcement in Dec. 1994 by Unisys
(which had obtained the patent for LZW from Sperry)
and CompuServe that they would start charging royal- Fig. 4. Arithmetic coding process for our example
ties to authors of software which included support for
GIF. The announcement resulted in a say revolution in
data compression that formed the core of the Usenet to the number of different symbols. The length of each
group comp.compression. The community decided that segment is proportional to the probability of each sym-
a patent-free replacement for GIF should be developed, bol. Than the output data is located in the corresponding
and within three months PNG was born. (For more segment according to the symbol. [8]
detailed history of PNG as well as software and much Consider an alphabet set A, B, C, D, E, F, @, where
more, go to the PNG website maintained by Greg Roelof, @ represent the end of message. The probability and
http://www.libpng.org/pub/png/.) segment range is shown in table IV.
• Compression over ModemsV.42 Now we take a string CAEE@ for example. The
The ITU-T Recommendation V.42 bis is a compres- initial interval [0, 1) is divided into seven interval, cor-
sion standard developed for using over a telephone net- responding to the number of symbols. The first symbol
work along with error-correcting procedures described in is C, which locate in the third segment, [0.3, 0.5).
CCITT Recommendation V.42. This algorithm is used Then continuously partition interval [0.3, 0.5) into seven
in modems connecting computers to remote users. The segments. The second symbol A is located in the first
algorithm operates in two modes, a transparent mode segment interval from 0.3 to 0.34. Continuously repeat
and a compressed mode. In the transparent mode, the partition until the end of string. The encoding step is
data are transmitted in uncompressed form, while in illustrated in Fig. 4. [4]
the compressed mode a LZW algorithm is used for The final interval is bounded by 0.33184 and 0.33320.
compression. [4] [2] [3] The range is also the probability of the string. Interval =
PC PA PE PE P@ =0.2*0.2*0.3*0.3*0.1 = 0.00036. If we
D. Arithmetic Coding calculate log2 1/0.00036 it would be almost 11.4. Thus
Arithmetic Coding is another coding algorithm based using 12 bits, we can encode this number.
on entropy encoding. Unlike Huffman coding which The final step is to pick an arbitrary number in the
uses variable-length codes to represent each symbols, range [0.33184, 0.33320), such as 0.332, or 0.33185.
Arithmetic Coding encode the whole data into one single When binary coding, a shortest binary fractional number
number within the interval of 0 and 1. The algorithm is the best suggested. Therefore the code 0.01010101 is
implement by separating 0 to 1 into segments according generated here, which would be equal to 0.3320.
Applications: Arithmetic coding is used in a variety of
lossless and lossy compression applications. It is a part of
many international standards. In the area of multimedia
there are some organizations that develop standards. The
International Standards Organization (ISO) and the Inter-
national Electrotechnical Commission (IEC) are industry
groups that work on multimedia standards, while the
International Telecommunications Union (ITU) works on
multimedia standards. Quite often these institutions work
together to create international standards. In the follow- Fig. 5. Examples of uniform (a) and non-uniform (b) scalar
ing of our survey, we will see how arithmetic coding is quantization.
used in JPEG, as an example of image compression.

IV. L OSSY DATA C OMPRESSION of output values, y. Many of the fundamental ideas of
Lossy compression is compression in which some quantization and compression are easily introduced in
of the information from the original message sequence the simple context of scalar quantization. Fig. 5 shows
is lost. This means the original sequences cannot be examples of uniform and non uniform quantizations. [2]
regenerated from the compressed sequence. Just because Vector quantization is a different type of quantization,
information is lost doesn’t mean the quality of the output which is typically implemented by selecting a set of
is reduced. For example, random noise has very high representatives from the input space, and then mapping
information content, but when present in an image or all other points in the space to the closest representative.
a sound file, we would typically be perfectly happy to The representatives could be fixed for all time and part
drop it. Also certain losses in images or sound might of the compression protocol, or they could be determined
be completely undetectable to a human viewer (e.g. for each file (message sequence) and sent as part of the
the loss of very high frequencies). For this reason, sequence. The most interesting aspect of vector quantiza-
lossy compression algorithms on images can often get tion is how one selects the representatives. Typically it is
a better compression ratio by a factor of 2 than lossless implemented using a clustering algorithm that finds some
algorithms with an undetectable loss in quality. However, number of clusters of points in the data. A representative
when quality does start degrading in an observable way, is then chosen for each cluster by either selecting one
it is important to make sure it degrades in a way that of the points in the cluster or using some form of
is least objectionable to the viewer (e.g., dropping ran- centroid for the cluster. Finding good clusters is a whole
dom pixels is probably more unpleasant than dropping interesting topic on its own. [9]
some color information). For these reasons, the ways Vector quantization is most effective when the vari-
most lossy compression techniques are used are highly ables along the dimensions of the space are correlated.
dependent on the media that is being compressed. Lossy Fig. 6 shows an example of possible representatives for a
compression for sound, for example, is very different height-weight chart. There is clearly a strong correlation
than lossy compression for images. between people’s height and weight and therefore the
In this section, I will go over two significant tech- representatives can be concentrated in areas of the space
niques which can be applied to various contexts, and that make physical sense, with higher densities in more
in the next sections we will see some of their major common regions. Using such representatives is very
applications in the real world. much more effective than separately using scalar quanti-
zation on the height and weight. [4] Vector quantization,
A. Vector and Scalar Quantization as well as scalar quantization, can be used as part of a
Quantization is the procedure of constraining some- lossless compression technique. In particular if in addi-
thing from a relatively large or continuous set of values tion to sending the closest representative, the coder sends
(such as the real numbers) to a relatively small discrete the distance from the point to the representative, then the
set (such as integers). original point can be reconstructed. The distance is often
Scalar quantization is one of the simplest and most referred to as the residual. In general this action alone
general idea for lossy compression. Scalar quantization would not cause compression, but in case the points
is a mapping of an input value x into a finite number have been tightly clustered around the representatives,
Fig. 6. Example of vector quantization.

then this approach can be very effective for lossless data


compression.
V. A C ASE S TUDY: L EMPEL -Z IV VS H UFFMAN
C ODING
Fig. 7. Simulation results of comparison between Huffman and LZ
Usually data compression algorithms do not take into algorithms based on our two tests.
account the type of data they are compressing. They can
be applied to computer data files, documents, images,
etc. In this section I will discusses two of the most wide data is being stored). This method is good at compressing
used algorithms for data compression as Ive mentioned text files because text files contain ASCII characters
before: Huffman coding and Lempel-Ziv coding (Ive run (which are stored as 8-bit binary values) but not so good
LZ 77 v01 coding algorithm). for graphics files, which may have repeating patterns of
In this section, I will run my simulation for these binary digits that might not be multiples of 8 bits.
two coding algorithms, and try to have a comparison
The simulation above shows lesser compression for
between them:
LZ than the Huffman Algorithm, but for large files, the
LZ algorithm is found to be more efficient. It can also
Test 1: ”Miss Issippi is living in Mississippi . but
adapt to different file formats better. LZ algorithm also
she misses Mississippi river everyday .”
has a lot of variations. Two distinct forms of the LZ
Test 2: ”Hello. I’m Mohammad. I’m running the
algorithm are LZ77 and LZ78. They have also evolved
simulation for two coding algorithms.”
into further forms. Popular forms are LZW, LZH, LZC
Simulation Analysis etc. The LZ algorithm is the more adaptive of the two to
Fig. 7 shows our simulation results for two test data. different file formats, although both the algorithms can
We used Java programming language for simulation. be suitably varied to achieve better compression.
As we know, Huffman coding uses a variable length The LZ algorithm can also be used in continuous
code for each of the elements within the information. data transmission, where the receiver maintains pointers
This normally involves analyzing the information to to the previously encountered patterns and can thus
determine the probability of elements within the informa- decode constantly. This is a very useful feature of the
tion. The most probable elements are coded with a few LZ algorithm.
bits and the least probable coded with a greater number The Huffman algorithm is better suited to smaller files,
of bits. although compression is not significant for very small
The great advantage of Huffman coding is that, al- files.
though each character is coded with a different number On the whole, the LZ algorithm is preferred over
of bits, the receiver will automatically determine the the Huffman algorithm, and a number of popular file
character whatever their order. compression utilities use variations of this algorithm.
But Lempel-Ziv algorithm builds a dictionary of Please note that it is rather obvious that the more the
frequently used groups of characters (or 8-bit binary words in a test data are similar, the more the compression
values). Before the file is decoded, the compression ratio is. This fact is also observable from our simulation
dictionary must be sent (if transmitting data) or stored (if results.
VI. M ULTIMEDIA C OMPRESSION : JPEG AND components can be converted via a linear transformation
MPEG into YCbCr components as the equation below shows:
Multimedia images have become a vital and ubiqui- [10]
tous component of everyday life. The amount of infor-
mation encoded in an image is quite large. Even with
the advances in bandwidth and storage capabilities, if
images were not compressed many applications would
be too costly. 2. Chrominance downsampling
The JPEG and the related MPEG format are examples Using YCbCr color space, we can also save space by
of multimedia compression. They are used very widely compressing resolution of Cb and Cr components. They
in practice, and also they use many of the compression are chrominance component and we can reduce them in
techniques we have been talking about throughout this order to make the image compressed. Because of the
survey, including Huffman codes, arithmetic codes, run importance of luminance for the eyes, we do not need
length coding and scalar quantization. the chrominance to be as frequent as luminance, so we
JPEG is used for still images and is the standard used can downsample it. Thus we can remove some of Cb
on the web for photographic images (the GIF format is and Cr elements. As a result, for instance transforming
often used for textual images). MPEG is used for video, RGB, 4:4:4 format into YCbCr 4:2:2, we would gain
based on a variant of JPEG (i.e. each frame is coded a data compression of ratio 1.5. However this step is
using a JPEG variant). Both JPEG and MPEG are lossy considered as an optional process.
formats. 3. Discrete cosine transform (DCT):
At this step, each component (Y, Cb, Cr) of every 88
A. Image Compression: JPEG Compression Algorithm block is then converted to a frequency domain repre-
Image compression is the process of reducing the sentation. The DCT equation is a complicated equation,
amount of data required to represent a digital image. having two cosine coefficients. We do not mention here,
This is done by removing all redundant or unnecessary for more details refer to JPEG standard.
information. An uncompressed image requires an enor- 4. Quantization:
mous amount of data to represent it. As we mentioned in the lossy compression section, for
JPEG is the image compression standard developed human eye, luminance is more important than chromi-
by the Joint Photographic Experts Group. JPEG is a nance. For eyes, seeing small differences in brightness
lossy compression algorithm that has been conceived to within a large area is more distinguishable than the
reduce the file size of natural, photographic-like true- exact strength of a high frequency brightness variation.
color images as much as possible without affecting the Using this property, we can greatly reduce information in
quality of the image as experienced by the human JPEG the high frequency components. JPEG coding does that
works on either full-color or gray-scale images; it does by simply dividing every components in the frequency
not handle bi-level (black and white) images, at least not domain by a constant for that component, and then
well. It doesn’t handle color mapped images either; you rounding to the nearest integer. So as a result, many of
have to pre-expand those into an unmapped full-color the higher frequency components are rounded to zero,
representation. JPEG works best on ”continuous tone” and most of the rest components become small positive
images. Images with many sudden jumps in color values or negative numbers, taking fewer bits for storage. The
will not compress well. There are a lot of parameters main lossy method in the whole process is done at this
to the JPEG compression process. By adjusting the step. The standard quantization for JPEG is provided in
parameters, you can trade off compressed image size table V. [?] However many other tables have been also
against reconstructed image quality. [10] defined and used.
In the followings we will discuss the steps used for JPEG 5. Entropy coding:
coding algorithm: Entropy coding is a type of lossless data compression.
1. Color space conversion Here we order image components in a zigzag form, then
the best compression results are achieved if the color using run-length encoding (RLE) algorithm that joins
components are independent (noncorrelated), such as in similar frequencies together to compress the sequence.
YCbCr, where most of the information is concentrated in We discusses RLE coding in the lossless compression
the luminance and less in the chrominance. RGB color section.
TABLE V
S TANDARD QUANTIZATION USED BY JPEG Fig. 9. The overal idea of MPEG coding

16 11 10 16 24 40 51 61
12 12 14 19 26 58 60 55
14 13 16 24 40 57 69 56
14 17 22 29 51 87 80 62
18 22 37 56 68 109 103 77
24 35 55 64 81 104 113 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99

taking less space. In theory, a video stream is a sequence


of discrete images. MPEG uses the special or temporal
relation between these successive frames for compres-
sion of video streams. This approach is the basic idea
in many of the approaches we have seen in this survey.
The more effectively a technique is in exploiting these
relations in a piece of data, the more effective it would
be for data compression.
The first public standard of the MPEG committee was
Fig. 8. JPEG compression steps
the MPEG-1, ISO/IEC 11172 that was first released in
1993. MPEG-1 video compression is based on the same
approach used in JPEG. Besides that, it also leverage
6. Huffman algorithm some methods for efficient coding of a video sequence.
After applying the previous steps, then the resulting [13]
data would be sequence of DCT coefficients. Now at this In MPEG coding algorithm, we only code the new
step which is the last step, we compress these coefficients parts of the video sequence along with the information
by using a Huffman coding or a arithmetic compression of the moving parts of the video. As an example,
algorithm. Mostly Huffman would be used which would consider having Figure 9, the upper three pictures. For
be considered as the second lossless compression in this compressing, we would just take into account the new
scheme. parts, which is shown in Figure 9, the bottom three
In general, the algorithm compresses images in sequences. [4]
different steps. Fig. 8 shows these different steps used The basic principle for video compression is the
for compression. Many other compression approaches image-to-image prediction. The first image in a sequence
for image and video compression are similar to JPEG. of images is I-frame. These frames shows beginning a
Aslo many of the variants of JPEG use the basic new scene thus do not need to be compress since they
concepts of JPEG scheme which are usually designed have no dependency outside of that image. But the other
for some specific applications. [11] [12] [2] frames may use part of the first image as a reference.
An image that is predicted from one reference image is
called a P-frame and an image which is bidirectionally
B. Video Compression: MPEG Compression Algorithm predicted from two other reference images is called a B-
Mostly people have some basic information about frame. So overall, we would have the followings frames
what MPEG compression is. It is used to compress video for MPEG coding:
files. MPEG is the short form of Moving Pictures Expert I-frames: self-contained; no need to be compress
Group, almost the same as JPEG. It is said that the P-frames: Predicted from last I or P reference frame
founding fathers of MPEG are Leonardo Chairiglione B-frames: Bidirectional; predicted from two references
(from Italy) and Hiroshi Yasuda (from Japan). The basic one in the past and one in the future, the best matching
idea for MPEG compression algorithm is to transform a would be considered.
stream of discrete samples into a bit stream of tokens, Figure 10 shows a sequence of these frames.
Fig. 10. A sequence of MPEG defined frames

Since I-frames are independent images, we compress


them like a single image. The particular technique used
by MPEG is a variant of the JPEG technique (the
color transformation and quantization steps are somehow
different). To decode any frame we only need to search
and find the closest previous I-frame to the current frame Fig. 11. MPEG overal coding process
and go from there. This is important for allowing reverse
playback, skip-ahead, or error-recovery. [4]
As we mentioned, our purpose for coding P-frames time MPEG encoding is only possible with the help of
is to find matching images, actually a set of pixels with powerful hardware devices. However, the decoder part
similar patterns in the previous reference frame and then is cheap since the decoder is given the motion vector
we would code just the difference between the P-frame and only needs to look up the block from the previous
and the match we have found. In order to find these image.
matches, MPEG algorithm divides P-frame into 16x16 Actually for B-frames, we look for reusable data in
blocks. both directions. The general approach is similar to what
Figure 11 shows the different processes used for we use in P-frames, but instead of just searching in the
encoding these different 16x16 blocks.. For each target previous I- or P-frame for a match, we would also search
block in the P-frame, the encoder finds a reference block the next I- or P-frame. If a good match is found in each of
in the previous P-frame or I-frame which is the best them, then we would take an average of the two reference
match for it. The reference block need not be aligned frames. If only one good match is found, then this one
on a 16-pixel boundary and can potentially be anywhere would be used as the reference. In these cases, the coder
in the image. Motion vector is the vector showing this needs to send some information saying which reference
direction. Once the match is found, the pixels of the has been used. [2] [2]
reference block are subtracted from the corresponding MPEG compression evaluation:
pixels in the target block. This gives a residual which Here we evaluate the effectiveness of MPEG coding
is very close to zero. This residual is coded using algorithm using a real world example. We can examine
a similar approach to JPEG algorithm. In addition to typical compression ratios for each frame type, and form
sending the coded residual, the coder also needs to an average weighted by the ratios in which the frames
send the motion vector, which is coded using Huffman are typically interleaved.
compression algorithm. Starting with a 356260 pixel, 24-bit color image,
The motivation for searching other locations in the typical compression ratios for MPEG-I are provided
reference image for a match is to allow for the efficient here:
encoding of motion. In particular if there is a moving
object in the sequence of images (consider a playing
avatar), or if the camera is just moving, then the best
match will not be in the same location in the image.
It should be noted that if no good match is found,
then the block would be coded the same as an I-frame. If one 356 260 frame requires 4.8 Kb, then for
Practically, this searching procedure for finding a good providing a good video at a rate of 30 frames/second,
match for each block is the most computationally costly then MPEG requires: 30 frames/sec 4.8 Kb/frame 8
part of MPEG encoding. With current technology, real- b/bit = 1.2 Mbits per second.
Thus far, we have been concentrating on the visual pressure on existing network connections in because of
component of MPEG. Adding a stereo audio stream will more data are being transmitted.
require roughly another 0.25 Mbits/sec, for a grand total One of the important and major roles of data com-
bandwidth of 1.45 Mbits/sec. This would be fit fine in the pression is using them in computer networks. However
1.5 Mbit per second capacity of a T1 line. In fact, this achieving a high compression ratio is necessary for
specific limit was a design goal in the MPEG design improving applications’ performance on networks with
that time. Real-life MPEG encoders are adaptive; they limited bandwidth, system throughput also plays an
track bit rate as they encode, and will dynamically adjust important role. If the compression ratio is too low, the
compression qualities to keep the bit rate within some network will remain saturated and performance gains
user-selected bound. This bit-rate control can also be will be minimal. Similarly, if compression speed is
important in other contexts. For example, video on a too low, the compressor will become the bottleneck.
multimedia CD-ROM must fit within the relatively poor Employee productivity can be dramatically impacted by
bandwidth of a typical CD-ROM drive. slow networks that result in poorly performing applica-
MPEG Applications: tions.
MPEG has so many applications in the real world. We Organizations have turned to network optimization as
enumerate some of them here: a way to combat the challenges of assuring application
1. Cable Television. Some TV systems send MPEG-II performance and help ensure timely transfer of large data
programming over cable television lines. sets across constrained network links. Many network
2. Direct Broadcast Satellite. MPEG video streams are data transfer optimization solutions are focused just on
received by a dish/decoder, which extracts the data for network-layer optimizations. Not only are these solutions
a standard NTSC television signal. are inflexible, they also fail to include optimizations
3. Media Vaults. Silicon Graphics, Storage Tech, and that can further enhance the performance of applications
other vendors are producing on-demand video systems, transferring data over network links. [14]
with twenty file thousand MPEG-encoded films on a
single installation. B. Packet-based or Session-based Compression
4. Real-Time Encoding. This is still the exclusive Many of network compression systems are packet-
province of professionals. Incorporating special-purpose based. Packet-based compression systems buffer packets
parallel hardware, real-time encoders can cost twenty to destined for a remote network with a decompressor.
fifty thousand dollars. [4] [2] [3] These packets are then compressed either within a single
time or as a group and then sent to the decompressor
VII. T ODAY ’ S DATA C OMPRESSION : where the process is reversed. Packet-based compression
A PPLICATIONS AND I SSUES has been available for many years and can be found in
A key in acceptance of data compression algorithms routers, VPN clients.
is finding an acceptable tradeoff between performance Packet-based compression systems have additional
and complexity. For performance we have two factors problems. When compressing packets, these systems
that run counter to each other and require another must choose between writing small packets to the net-
compromise. These factors are the end-user perception work and performing additional work to aggregate and
of compression (e.g. image quality in image compres- encapsulate multiple packets. Neither option produces
sion) and the data rate compression achieved. System optimal results. Writing small packets to the network
complexity eventually defines the cost of encoding and increases TCP/IP header overhead, while aggregating
decoding devices. Here we briefly discuss some todays and encapsulating packets adds encapsulation headers to
data compression issues, and at the end will briefly the stream.
discuss some research works towards energy efficiency
which nowadays is the most concerning field of study as C. Dictionary Size for Compression
we are turning in to a green computing. One limitation of that almost all compression utilities
have in common is limited storage space.
A. Networking Some utilities, such as GNUzip (gzip), store as little
Today, with the increasing number of users and tele- as 64 kilobytes (KBs) of data. Others techniques, such
working along with emerging application deployment as disk-based compression systems, can store as much
models which use cloud computing, causes additional as 1 TByte of data.
of data among the sensors needs energy efficiency, low
latency and also high accuracy.
Currently, if sensor system designers want to compress
acquired data, they must either develop application-
specific compression algorithms or use off-the-shelf al-
gorithms not designed for resource-constrained sensor
nodes.
Major attempts have resulted to implement a Sensor-
Lempel-Ziv (S-LZW) compression algorithm designed
Fig. 12. Compressing 512B of data in a 256B-block system
especially for WSNs. While developing Sensor LZW and
some simple, but effective variations to this algorithm,
Christopher Sadler and Margaret Martonosi in their pa-
Similar to requests to a website, not all bytes trans- per [15] showed how different amounts of compression
ferred on the network repeat with the same frequency. can lead to energy savings on both the compressing node
Some byte patterns occur with great frequency because and throughout the network and that the savings depends
they are part of a popular document or common net- heavily on the radio hardware. They achieved signifi-
work protocol. Other byte patterns occur only once cant energy improvements by devising computationally-
and are never repeated again. The relationship between efficient lossless compression algorithms on the source
frequently repeating byte sequences and less frequently node. These reduce the amount of data that must be
repeating ones is seen in Zipfs law. (%80 of requests are passed through the network, and thus have energy ben-
for %20 of data; data with higher ranks.) efits that are multiplicative with the number of hops
the data travels through the network. Their evaluation
D. Block-based or Byte-based Compression showed reduction in amount of transmitting data by a
factor of 4.5.
Block-based compression systems store segments of Regarding this trend for designing efficient data com-
previously transferred data flowing across the network. pression algorithms in WSNs, R.Vidhyapriya1 and P.
When these blocks are encountered a second time, Vanathi designed and implemented two lossless data
references to the blocks are transmitted to the remote compression algorithms integrated with the shortest path
appliance, which then reconstructs the original data. routing technique to reduce the raw data size and to
A critical shortcoming of block-based systems is that accomplish optimal trade-off between rate, energy, and
repetitive data almost never is exactly the length of accuracy in a sensor network. [16]
a block. As a result, matches are usually only partial
matches, which do not compress some repetitive data. VIII. C ONCLUSION
Figure 12 illustrates what happens when a system using Today, with growing amount of data storage and infor-
a 256-byte block size attempts to compress 512 bytes of mation transmission, data compression techniques have
data. [14] [4] a significant role. Even with the advances in bandwidth
and storage capabilities, if data were not compressed,
E. Energy Efficiency many applications would be too costly and the users
The most recent works are being done in the area of could not use them. In this research survey, I attempted
energy efficiency, especially regarding Wireless Sensor to introduce two types of compression, lossless and
Networks (WSNs). Just as a reminder that a wireless lossy compression, and some major concepts, algorithms
sensor network consists of spatially distributed sensors and approaches in data compression and discussed their
to monitor physical or environmental conditions, such different applications and the way they work. We also
as temperature, sound, vibration, pressure, motion or evaluated two of the most important compression al-
pollutants and to cooperatively pass their data through gorithms based on simulation results. Then as my next
the network to a main location. Nowadays lots of papers contribution, I thoroughly discussed two major everyday
and research works have been devoted to WSNs. Size applications regarding data compression; JPEG as an ex-
and cost constraints on sensors result in constraints on re- ample for image compression and MPEG as an example
sources on them such as energy, memory, computational of video compression in our everyday life. At the end
speed and communications bandwidth. The vast sharing of this survey I discussed major issues in leveraging
data compression algorithms and the state-of-the art
research works done regarding energy saving in top-
world-discussed area in networking which is Wireless
Sensor Networks.
R EFERENCES
[1] D. Huffman, “A method for the construction of minimum-
redundancy codes, huffman original paper,” Proceedings of the
I.R.E, 1952.
[2] D. Lelewer and D. Hirschberg, “Data compression,” ACM
Computing Surveys, 1987.
[3] R. Pasco, “Source coding algorithms for fast data compression,”
Ph.D. dissertation, Stanford University, 1976.
[4] K. Sayood, “Lossless compression handbook,” Academic Press,
2003.
[5] C. Zeeh, “The lempel ziv algorithm,” Seminar Famous Algo-
rithms, 2003.
[6] T. Welch, “A technique for high-performance data compres-
sion,” IEEE Computer, 1984.
[7] P. Deutsch., “Deflate compressed data format specification
version 1.3,” RFC 1951, http://www.faqs.org/rfcs/rfc1951.htm,
1996.
[8] G. J. Rissanen, J.J.; Langdon, “Arithmetic coding,” IBM Journal
of Research and Development, 1979.
[9] A. Gersho and R. Gray, “Vector quantization and signal com-
pression,” Kluwer Academic Publishers, 1991.
[10] JPEG2000, http://www.jpeg.org/jpeg2000/, .
[11] G. K. Wallace, “The jpeg still picture compression standard,”
ACM digital multimedia systems, vol. 34, 1991.
[12] A Guide to Image Processing and Picture Management. Gower
Publishing Limited, 1994.
[13] “Digital video coding standards and their role in video commu-
nications,” 1995.
[14] A. C. W. Paper, “An explanation of video compression tech-
niques,” , 2008.
[15] C. M. Sadler and M. Martonosi, “Data compression algorithms
for energy-constrained devices in delay tolerant networks,”
Proceeding of ACM SenSys, 2006.
[16] R. Vidhyapriya1 and P. Vanathi, “Energy efficient data compres-
sion in wireless sensor networks,” The International Journal of
Information Technology, 2009.

You might also like