Fundamentals of Compression: Prepared By: Haval Akrawi

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

FUNDAMENTALS OF COMPRESSION

Prepared by: Haval Akrawi

1
What is Compression?
• Reduce the size of data.

• Also, Compression is a way to reduce the number of bits in a


frame but retaining its meaning.

• Advantages:
» Reduce storage needed
» Reduce transmission cost/latency/bandwidth.

2
Data Compression Methods

3
Lossless compression
• Lossless compression is a class of data compression that
allows the original data to be perfectly reconstructed from
the compressed data.
• Redundant data is removed in compression and added
during decompression.
• Most lossless compression programs do two things in
sequence: the first step generates a statistical model for the
input data, and the second step uses this model to map input
data to bit sequences in such a way that "probable" (e.g.
frequently encountered) data will produce shorter output
than "improbable" data.

4
Method 1:Run-length encoding
• Simplest method of compression.
• How: replace consecutive repeating occurrences of a symbol
by 1 occurrence of the symbol itself, then followed by the
number of occurrences.

• The method can be more efficient if the data uses only 2


symbols (0s and 1s) in bit patterns and 1 symbol is more
frequent than another.

5
Method 2:Huffman Coding
 Assign fewer bits to symbols that occur more frequently and
more bits to symbols appear less often.
 There’s no unique Huffman code and every Huffman code has
the same average code length.
 Algorithm:
① Make a leaf node for each code symbol
Add the generation probability of each symbol to the leaf node
② Take the two leaf nodes with the smallest probability and connect them into
a new node
Add 1 or 0 to each of the two branches
The probability of the new node is the sum of the probabilities of the
two connecting nodes
③ If there is only one node left, the code construction is completed. If not, go
back to (2)

6
Huffman Algorithm:
• For example,

7
How the encoding and decoding process
takes place?
• Encoding:

• Decoding:

8
Method 3:Lempel Ziv Encoding
• It is dictionary-based encoding

• Basic idea:
 Create a dictionary(a table) of strings used during
communication.

 If both sender and receiver have a copy of the


dictionary, then previously-encountered strings can be
substituted by their index in the dictionary.

9
Contd...,
 This compression has 2 phases:
 Building an indexed dictionary
 Compressing a string of symbols
• Algorithm for lempel ziv encoding:
 Extract the smallest substring that cannot be found in the
remaining uncompressed string.
 Store that substring in the dictionary as a new entry and
assign it an index value
 Substring is replaced with the index found in the
dictionary
 Insert the index and the last character of the substring
into the compressed string

10
Lempel Ziv Compression
• Compression
example,

11
Lossy Compression
• Lossy compression is the converse of lossless data
compression.

• It is Used for compressing images and video files.

• Methods of lossy compression:


 JPEG: compress pictures and graphics
 MPEG:compress video
 MP3: compress audio

12
Method 1:JPEG Encoding
• Used to compress pictures and graphics.
• In JPEG, a grayscale picture is divided into 8x8 pixel
blocks to decrease the number of calculations.
• Basic idea:
 Change the picture into a linear (vector) sets of numbers that
reveals the redundancies.
 The redundancies is then removed by one of lossless.

13
JPEG Encoding- DCT
• DCT: Discrete Concise Transform
• DCT transforms the 64 values in 8x8 pixel block in a way that
the relative relationships between pixels are kept but the
redundancies are revealed.
• Example:
A gradient grayscale

14
Quantization & Compression
 Quantization:
 After T table is created, the values are quantized to
reduce the number of bits needed for encoding.
 Quantization divides the number of bits by a constant,
then drops the fraction. This is done to optimize the
number of bits and the number of 0s for each particular
application.

• Compression:
 Quantized values are read from the table and redundant
0s are removed.
 To cluster the 0s together, the table is read diagonally in
an zigzag fashion. The reason is if the table doesn’t have
fine changes, the bottom right corner of the table is all 0s.
 JPEG usually uses lossless run-length encoding at the
compression phase.
15
JPEG Encoding

16
Method 2:MPEG Encoding
• Used to compress video.

• Basic idea:
 Each video is a rapid sequence of a set of frames. Each
frame is a spatial combination of pixels, or a picture.
 Compressing video =
spatially compressing each frame
+
temporally compressing a set of frames.

17
Types of MPEG compression
• Spatial Compression
 Each frame is spatially compressed by JPEG.
• Temporal Compression
 Redundant frames are removed.
 For example, in a static scene in which someone is talking, most
frames are the same except for the segment around the speaker’s
lips, which changes from one frame to the next.

18
Method 3:Audio(or)Mp3 Encoding
• Used for speech or music
 Speech: compress a 64 kHz digitized signal
 Music: compress a 1.411 MHz signal

• Two categories of techniques:


 Predictive encoding
 Perceptual encoding

19
Categories:
 Predictive Encoding
 Only the differences between samples are encoded, not
the whole sample values.
 Several standards: GSM (13 kbps), G.729 (8 kbps), and
G.723.3 (6.4 or 5.3 kbps)

• Perceptual Encoding: MP3


 CD-quality audio needs at least 1.411 Mbps and cannot
be sent over the Internet without compression.
 MP3 (MPEG audio layer 3) uses perceptual encoding
technique to compress audio.

20
21

You might also like