SlideShare a Scribd company logo
1 of 40
Data Compression
Presented to: Prof. Dr. Maha Sharkas
presented by: Sherif Mohamed

1
Data Compression
Outline
1)
2)
3)
4)
5)
6)

Introduction.
Types of Data Compression.
Lossless Compression.
Lossless Algorithms.
Lossy Compression.
Lossy Algorithms .
2
Data Compression
• It is the process of reducing the amount of
data required to represent a given quantity of
information.
• Save time and help to optimize resources
i. In sending data over communication line:
less time to transmit and less storage to
host.
• Reduce length of data transmission time over
the network.
3
Types of Data Compression
1. Lossless Compression.
2. Lossy Compression.

4
Data Compression Algorithm
• Lossless Compression
If the compressed data is reconstructed and
the original data is obtain without any loss of
information then this technique is called
lossless compression.

5
Types of Data Compression
• Lossy Compression
If the compressed data is reconstructed and
the approximation of original data is obtain
and loss of information occurs then this
technique is called lossy compression.
The original message can never be recovered
exactly as it was before it was compressed.

6
Types of Data Compression

Lossless

Original Data

Compressed
Data

Original Data
Approximated

7
Data Compression Algorithm

8
Lossless Algorithm
• Huffman Encoding
 There’s no unique Huffman code.
 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)

9
Huffman Coding
• z

10
Huffman Coding
• Encoding

• Decoding

11
Lossless Algorithm
• Lempel Ziv Walsh (LZW) Encoding
• It is dictionary based encoding
• Basic idea:
 Create a dictionary or a code 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.

• LZW to compress text, executable code and similar
data files to about one half their original size.
12
LZW Coding
 Have 2 phases:
 Building an indexed dictionary
 Compressing a string of symbols

• Algorithm:
 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
13
LZW Coding
• Lempel Ziv Compression

14
15
LZW Coding
• Lempel Ziv Decompression

16
17
Lossless Algorithm
• Run Length Encoding
• Simplest method of compression.
• Replace consecutive repeating occurrences of
a symbol by 1 occurrence of the symbol itself,
then followed by the number of occurrences.

18
Run Length Coding
• 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.

19
Lossy Algorithm
• Used for compressing images and video files (our
eyes cannot distinguish subtle changes, so lossy data
is acceptable).
• These methods are cheaper, less time and space.
• Several methods:
 JPEG: compress pictures and graphics
 MPEG: compress video
 MP3: compress audio

20
Lossy Algorithm
• 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

21
JPEG Encoding

22
JPEG Encoding
• DCT(Discrete Cosine Transform)
• Image is divided into blocks of 8*8 pixels.
• For grey-scale images, pixel is represented by 8-bits.
• For color images, pixel is represented by 24-bits or
three 8-bit groups.

23
JPEG Encoding
• DCT takes an 8*8 matrix and produces another 8*8
matrix and its values represent by this equation:

T[i][j] = 0.25 C(i) C(j) ∑ ∑ P[x][y] Cos(2x+1)iπ/16
* Cos (2y+1)jπ/16
 i = 0, 1, …7, j = 0, 1, …7
 C(i) = 1/√2, i =0
= 1 otherwise
T contains values called ‘Spatial frequencies’
24
JPEG Encoding
• T[0][0] is called the DC coefficient, related to
average values in the array, Cos 0 = 1
• Other values of T are called AC coefficients, cosine
functions of higher frequencies
 Case 1: all P’s are same, image of single color with no variation
at all, AC coefficients are all zeros.
 Case 2: little variation in P’s, many, not all, AC coefficients are
zeros.
 Case 3: large variation in P’s, a few AC coefficients are zeros.
25
JPEG Encoding

26
JPEG Encoding
P-matrix
T-matrix
• 20 30 40 50 60 …
720 -182 0 -19 0 …
30 40 50 60 70
-182 0 0 0 0
40 50 60 70 80
0
0 0 0 0
50 60 70 80 90
-19 0 0 0 0
60 70 80 90 100
0
0 0 0 0
…
…
‘Uniform color change and little fine detail, easier to
compress after DCT’
27
JPEG Encoding
P-matrix
T-matrix
• 100 150 50 100 100 …
835 15 -17 59 5…
200 10 110 20 200
46 -60 -36 11 14
10 200 130 30 200
-32 -9 130 105 -37
100 10 90 190 120
59 -3 27 -12 30
10 200 200 120 90
50 -71 -24 -56 -40
….
….
‘Large color change, difficult to compress after DCT’
28
JPEG Encoding
• Quantization
• Provides an way of ignoring small differences in an
image that may not be perceptible.
• Another array Q is obtained by dividing each
element of T by some number and rounding-off to
nearest integer ( The loss is occur in this step)

29
JPEG Encoding
T-matrix
Q-matrix
• 152 0 -48 0 -8…
15 0 -5 0 -1…
0 0 0 0 0
0 0 0 0 0
-48 0 38 0 -3
-5 0 4 0 0
0 0 0 0 0
0 0 0 0 0
-8 0 -3 0 13
-1 0 0 0 1
…
…
‘Divide by 10 and round-off ’
.
30
JPEG Encoding
• Dividing T-elements by the same number is not
practical, may result in too much loss.
• Retain the effects of lower frequencies as much as
possible.
• To define a quantization array Q, then
Q[i][j] = Round (T[i][j] ÷ U[i][j]),
i = 0, 1,.........7, j = 0, 1, …7

31
JPEG Encoding
• U = 1 3 5 7 9… Q= 152 0 -10 0 -1 …
3 5 7 9 11
0 0 0 0 0
5 7 9 11 13
-10 0 4 0 0
7 9 11 13 15
0 0 0 0 0
9 11 13 15 17
-1 0 0 0 0
…
…
‘Q can be well compressed due to redundant
elements’
32
JPEG Encoding
• Compression
 Quantized values are read from the matrix and redundant
0s are removed.
 To cluster the 0s together, the matrix is read diagonally
in an zigzag fashion. The reason is if the matrix doesn’t
have fine changes, the bottom right corner of the matrix
is all 0s.
 JPEG usually uses lossless run-length encoding at the
compression phase.

33
JPEG Encoding

34
JPEG Encoding

8x8
pixel
block

Discrete
Cosine
Transform

Quantization

Run Length,
Huffman
Encoding

to .jpg file

35
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.

36
MPEG Encoding
• Spatial Compression
 Each frame is spatially compressed by JPEG.
• Temporal Compression
 Redundant frames are removed.
 Usually little difference from one to the next frame
is suitable for compression.
{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}.
 Three frames: I, P, B.
37
MPEG Encoding
• I (intra-picture) frame: Just a JPEG encoded
image.
• P (predicted) frame: Encoded by computing
the differences between a current and a
previous frame.
• B (bidirectional) frame: Similar to P-frame
except that it is interpolated between previous
and future frame.
38
MPEG Encoding
• order in which to transmit: I – P – I
P is sandwiched between groups of B
P is the difference from the previous I-frame
B is interpolated from the nearest I and P
order in which to display I – B – B – P – B – B – I

39
Thank You
40

More Related Content

What's hot

Dictionary Based Compression
Dictionary Based CompressionDictionary Based Compression
Dictionary Based Compression
anithabalaprabhu
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 text
Jay Patel
 

What's hot (20)

Text compression
Text compressionText compression
Text compression
 
Fundamentals of Data compression
Fundamentals of Data compressionFundamentals of Data compression
Fundamentals of Data compression
 
Data compression
Data compressionData compression
Data compression
 
Audio compression
Audio compressionAudio compression
Audio compression
 
Digital Image Processing - Image Compression
Digital Image Processing - Image CompressionDigital Image Processing - Image Compression
Digital Image Processing - Image Compression
 
Video compression
Video compressionVideo compression
Video compression
 
Data compression
Data  compressionData  compression
Data compression
 
Data compression
Data compression Data compression
Data compression
 
Audio compression 1
Audio compression 1Audio compression 1
Audio compression 1
 
Compression: Video Compression (MPEG and others)
Compression: Video Compression (MPEG and others)Compression: Video Compression (MPEG and others)
Compression: Video Compression (MPEG and others)
 
Lzw coding technique for image compression
Lzw coding technique for image compressionLzw coding technique for image compression
Lzw coding technique for image compression
 
JPEG
JPEGJPEG
JPEG
 
Comparison between Lossy and Lossless Compression
Comparison between Lossy and Lossless CompressionComparison between Lossy and Lossless Compression
Comparison between Lossy and Lossless Compression
 
Audio compression
Audio compressionAudio compression
Audio compression
 
Dictionary Based Compression
Dictionary Based CompressionDictionary Based Compression
Dictionary Based Compression
 
Multimedia image compression standards
Multimedia image compression standardsMultimedia image compression standards
Multimedia image compression standards
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 text
 
Analog Video
Analog Video Analog Video
Analog Video
 
DCT image compression
DCT image compressionDCT image compression
DCT image compression
 
Huffman Coding
Huffman CodingHuffman Coding
Huffman Coding
 

Viewers also liked

Data compression introduction
Data compression introductionData compression introduction
Data compression introduction
Rahul Khanwani
 
G zip compresser ppt
G zip compresser pptG zip compresser ppt
G zip compresser ppt
gaurav kumar
 
Data compression
Data compressionData compression
Data compression
Nizar Sbaih
 
Data Compression In SQL
Data Compression In SQLData Compression In SQL
Data Compression In SQL
Boosh Booshan
 
Text compression in LZW and Flate
Text compression in LZW and FlateText compression in LZW and Flate
Text compression in LZW and Flate
Subeer Rangra
 

Viewers also liked (19)

Data compression introduction
Data compression introductionData compression introduction
Data compression introduction
 
Data Compression Technique
Data Compression TechniqueData Compression Technique
Data Compression Technique
 
data compression technique
data compression techniquedata compression technique
data compression technique
 
4 data compression
4 data compression4 data compression
4 data compression
 
Compression techniques
Compression techniquesCompression techniques
Compression techniques
 
image compression ppt
image compression pptimage compression ppt
image compression ppt
 
G zip compresser ppt
G zip compresser pptG zip compresser ppt
G zip compresser ppt
 
Data compression
Data compressionData compression
Data compression
 
Data Compression In SQL
Data Compression In SQLData Compression In SQL
Data Compression In SQL
 
Data compression techniques
Data compression techniquesData compression techniques
Data compression techniques
 
Text compression in LZW and Flate
Text compression in LZW and FlateText compression in LZW and Flate
Text compression in LZW and Flate
 
Spandana image processing and compression techniques (7840228)
Spandana   image processing and compression techniques (7840228)Spandana   image processing and compression techniques (7840228)
Spandana image processing and compression techniques (7840228)
 
A new algorithm for data compression technique using vlsi
A new algorithm for data compression technique using vlsiA new algorithm for data compression technique using vlsi
A new algorithm for data compression technique using vlsi
 
Image compression
Image compressionImage compression
Image compression
 
Data compression in Modern Application
Data compression in Modern ApplicationData compression in Modern Application
Data compression in Modern Application
 
Evm Test Impairements
Evm Test ImpairementsEvm Test Impairements
Evm Test Impairements
 
An Implementation of Quadtree for Image Compression
An Implementation of Quadtree for Image CompressionAn Implementation of Quadtree for Image Compression
An Implementation of Quadtree for Image Compression
 
Adaptive Huffman and Lossless Compression Techniques - Documentation
Adaptive Huffman and Lossless Compression Techniques - DocumentationAdaptive Huffman and Lossless Compression Techniques - Documentation
Adaptive Huffman and Lossless Compression Techniques - Documentation
 
Computer software 2
Computer software 2Computer software 2
Computer software 2
 

Similar to Data compression

CyberSec_JPEGcompressionForensics.pdf
CyberSec_JPEGcompressionForensics.pdfCyberSec_JPEGcompressionForensics.pdf
CyberSec_JPEGcompressionForensics.pdf
MohammadAzreeYahaya
 
image compression in data compression
image compression in data compressionimage compression in data compression
image compression in data compression
Zaabir Ali
 
Compression of digital voice and video
Compression of digital voice and videoCompression of digital voice and video
Compression of digital voice and video
sangusajjan
 

Similar to Data compression (20)

image basics and image compression
image basics and image compressionimage basics and image compression
image basics and image compression
 
lossy compression JPEG
lossy compression JPEGlossy compression JPEG
lossy compression JPEG
 
notes_Image Compression_edited.ppt
notes_Image Compression_edited.pptnotes_Image Compression_edited.ppt
notes_Image Compression_edited.ppt
 
Data compression
Data compressionData compression
Data compression
 
Source coding
Source codingSource coding
Source coding
 
image processing for jpeg presentati.ppt
image processing for jpeg presentati.pptimage processing for jpeg presentati.ppt
image processing for jpeg presentati.ppt
 
Jpeg compression
Jpeg compressionJpeg compression
Jpeg compression
 
CyberSec_JPEGcompressionForensics.pdf
CyberSec_JPEGcompressionForensics.pdfCyberSec_JPEGcompressionForensics.pdf
CyberSec_JPEGcompressionForensics.pdf
 
Squashed JPEG Image Compression via Sparse Matrix
Squashed JPEG Image Compression via Sparse MatrixSquashed JPEG Image Compression via Sparse Matrix
Squashed JPEG Image Compression via Sparse Matrix
 
SQUASHED JPEG IMAGE COMPRESSION VIA SPARSE MATRIX
SQUASHED JPEG IMAGE COMPRESSION VIA SPARSE MATRIXSQUASHED JPEG IMAGE COMPRESSION VIA SPARSE MATRIX
SQUASHED JPEG IMAGE COMPRESSION VIA SPARSE MATRIX
 
Squashed JPEG Image Compression via Sparse Matrix
Squashed JPEG Image Compression via Sparse MatrixSquashed JPEG Image Compression via Sparse Matrix
Squashed JPEG Image Compression via Sparse Matrix
 
Compression: Images (JPEG)
Compression: Images (JPEG)Compression: Images (JPEG)
Compression: Images (JPEG)
 
Image compression and jpeg
Image compression and jpegImage compression and jpeg
Image compression and jpeg
 
image compression in data compression
image compression in data compressionimage compression in data compression
image compression in data compression
 
Why Image compression is Necessary?
Why Image compression is Necessary?Why Image compression is Necessary?
Why Image compression is Necessary?
 
Compression of digital voice and video
Compression of digital voice and videoCompression of digital voice and video
Compression of digital voice and video
 
Data Compression
Data CompressionData Compression
Data Compression
 
SOC Application Studies: Image Compression
SOC Application Studies: Image CompressionSOC Application Studies: Image Compression
SOC Application Studies: Image Compression
 
Jpeg
JpegJpeg
Jpeg
 
Jpeg standards
Jpeg   standardsJpeg   standards
Jpeg standards
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 

Data compression

  • 1. Data Compression Presented to: Prof. Dr. Maha Sharkas presented by: Sherif Mohamed 1
  • 2. Data Compression Outline 1) 2) 3) 4) 5) 6) Introduction. Types of Data Compression. Lossless Compression. Lossless Algorithms. Lossy Compression. Lossy Algorithms . 2
  • 3. Data Compression • It is the process of reducing the amount of data required to represent a given quantity of information. • Save time and help to optimize resources i. In sending data over communication line: less time to transmit and less storage to host. • Reduce length of data transmission time over the network. 3
  • 4. Types of Data Compression 1. Lossless Compression. 2. Lossy Compression. 4
  • 5. Data Compression Algorithm • Lossless Compression If the compressed data is reconstructed and the original data is obtain without any loss of information then this technique is called lossless compression. 5
  • 6. Types of Data Compression • Lossy Compression If the compressed data is reconstructed and the approximation of original data is obtain and loss of information occurs then this technique is called lossy compression. The original message can never be recovered exactly as it was before it was compressed. 6
  • 7. Types of Data Compression Lossless Original Data Compressed Data Original Data Approximated 7
  • 9. Lossless Algorithm • Huffman Encoding  There’s no unique Huffman code.  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) 9
  • 12. Lossless Algorithm • Lempel Ziv Walsh (LZW) Encoding • It is dictionary based encoding • Basic idea:  Create a dictionary or a code 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. • LZW to compress text, executable code and similar data files to about one half their original size. 12
  • 13. LZW Coding  Have 2 phases:  Building an indexed dictionary  Compressing a string of symbols • Algorithm:  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 13
  • 14. LZW Coding • Lempel Ziv Compression 14
  • 15. 15
  • 16. LZW Coding • Lempel Ziv Decompression 16
  • 17. 17
  • 18. Lossless Algorithm • Run Length Encoding • Simplest method of compression. • Replace consecutive repeating occurrences of a symbol by 1 occurrence of the symbol itself, then followed by the number of occurrences. 18
  • 19. Run Length Coding • 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. 19
  • 20. Lossy Algorithm • Used for compressing images and video files (our eyes cannot distinguish subtle changes, so lossy data is acceptable). • These methods are cheaper, less time and space. • Several methods:  JPEG: compress pictures and graphics  MPEG: compress video  MP3: compress audio 20
  • 21. Lossy Algorithm • 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 21
  • 23. JPEG Encoding • DCT(Discrete Cosine Transform) • Image is divided into blocks of 8*8 pixels. • For grey-scale images, pixel is represented by 8-bits. • For color images, pixel is represented by 24-bits or three 8-bit groups. 23
  • 24. JPEG Encoding • DCT takes an 8*8 matrix and produces another 8*8 matrix and its values represent by this equation: T[i][j] = 0.25 C(i) C(j) ∑ ∑ P[x][y] Cos(2x+1)iπ/16 * Cos (2y+1)jπ/16  i = 0, 1, …7, j = 0, 1, …7  C(i) = 1/√2, i =0 = 1 otherwise T contains values called ‘Spatial frequencies’ 24
  • 25. JPEG Encoding • T[0][0] is called the DC coefficient, related to average values in the array, Cos 0 = 1 • Other values of T are called AC coefficients, cosine functions of higher frequencies  Case 1: all P’s are same, image of single color with no variation at all, AC coefficients are all zeros.  Case 2: little variation in P’s, many, not all, AC coefficients are zeros.  Case 3: large variation in P’s, a few AC coefficients are zeros. 25
  • 27. JPEG Encoding P-matrix T-matrix • 20 30 40 50 60 … 720 -182 0 -19 0 … 30 40 50 60 70 -182 0 0 0 0 40 50 60 70 80 0 0 0 0 0 50 60 70 80 90 -19 0 0 0 0 60 70 80 90 100 0 0 0 0 0 … … ‘Uniform color change and little fine detail, easier to compress after DCT’ 27
  • 28. JPEG Encoding P-matrix T-matrix • 100 150 50 100 100 … 835 15 -17 59 5… 200 10 110 20 200 46 -60 -36 11 14 10 200 130 30 200 -32 -9 130 105 -37 100 10 90 190 120 59 -3 27 -12 30 10 200 200 120 90 50 -71 -24 -56 -40 …. …. ‘Large color change, difficult to compress after DCT’ 28
  • 29. JPEG Encoding • Quantization • Provides an way of ignoring small differences in an image that may not be perceptible. • Another array Q is obtained by dividing each element of T by some number and rounding-off to nearest integer ( The loss is occur in this step) 29
  • 30. JPEG Encoding T-matrix Q-matrix • 152 0 -48 0 -8… 15 0 -5 0 -1… 0 0 0 0 0 0 0 0 0 0 -48 0 38 0 -3 -5 0 4 0 0 0 0 0 0 0 0 0 0 0 0 -8 0 -3 0 13 -1 0 0 0 1 … … ‘Divide by 10 and round-off ’ . 30
  • 31. JPEG Encoding • Dividing T-elements by the same number is not practical, may result in too much loss. • Retain the effects of lower frequencies as much as possible. • To define a quantization array Q, then Q[i][j] = Round (T[i][j] ÷ U[i][j]), i = 0, 1,.........7, j = 0, 1, …7 31
  • 32. JPEG Encoding • U = 1 3 5 7 9… Q= 152 0 -10 0 -1 … 3 5 7 9 11 0 0 0 0 0 5 7 9 11 13 -10 0 4 0 0 7 9 11 13 15 0 0 0 0 0 9 11 13 15 17 -1 0 0 0 0 … … ‘Q can be well compressed due to redundant elements’ 32
  • 33. JPEG Encoding • Compression  Quantized values are read from the matrix and redundant 0s are removed.  To cluster the 0s together, the matrix is read diagonally in an zigzag fashion. The reason is if the matrix doesn’t have fine changes, the bottom right corner of the matrix is all 0s.  JPEG usually uses lossless run-length encoding at the compression phase. 33
  • 36. 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. 36
  • 37. MPEG Encoding • Spatial Compression  Each frame is spatially compressed by JPEG. • Temporal Compression  Redundant frames are removed.  Usually little difference from one to the next frame is suitable for compression. {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}.  Three frames: I, P, B. 37
  • 38. MPEG Encoding • I (intra-picture) frame: Just a JPEG encoded image. • P (predicted) frame: Encoded by computing the differences between a current and a previous frame. • B (bidirectional) frame: Similar to P-frame except that it is interpolated between previous and future frame. 38
  • 39. MPEG Encoding • order in which to transmit: I – P – I P is sandwiched between groups of B P is the difference from the previous I-frame B is interpolated from the nearest I and P order in which to display I – B – B – P – B – B – I 39