SlideShare a Scribd company logo
Digital Image Processing
1
Module-IV
IMAGE COMPRESSION
2
Huffman Coding
• Huffman coding is a popular compression technique that
assigns variable length codes (VLC) to symbols, so that
the most frequently occurring symbols have the shortest
codes.
• On decompression the symbols are reassigned their
original fixed length codes.
3
• The idea is to use short bit strings to represent
the most frequently used characters
• and to use longer bit strings to represent less
frequently used characters.
4
• That is, the most common characters, usually space, e,
and t are assigned the shortest codes.
• In this way the total number of bits required to transmit
the data can be considerably less than the number
required if the fixed length ASCII representation is used.
• A Huffman code is a binary tree with branches assigned
the value 0 or 1.
5
6
Huffman Algorithm
• To each character, associate a binary tree consisting of
just one node.
• To each tree, assign the character’s frequency, which is
called the tree’s weight.
• Look for the two lightest-weight trees. If there are
more than two, choose among them randomly.
7
• Merge the two into a single tree with a new root
node whose left and right sub trees are the two
we chose.
• Assign the sum of weights of the merged trees as
the weight of the new tree.
• Repeat the previous step until just one tree is left.
8
Huffman Coding Example
• Character frequencies
– A: 20% (.20)
– B: 9% (.09)
– C: 15%
– D: 11%
– E: 40%
– F: 5%
• No other characters in the document
9
Huffman Code
10
C
.15
A
.20
D
.11
F
.05
BF
.14
B
.09
0 1
E
.4
Huffman Code
• Codes
– A: 010
– B: 0000
– C: 011
– D: 001
– E: 1
– F: 0001
• Note
– None are prefixes of another
11
ABCDEF
1.0
E
.4
C
.15
A
.20
D
.11
F
.05
BF
.14
AC
.35
BFD
.25
ABCDF
.6
B
.09
0
0
0
0
0
1
1
1
1
1
Huffman Coding
• TENNESSEE
9
0/ 1
5 e(4)
0/ 1
s(2) 3
0/ 1
t(1) n(2)
• ENCODING
• E : 1
• S : 00
• T : 010
• N : 011
Average code length = (1*4 +
2*2 + 3*2 + 3*1) / 9 = 1.89
12
Average Code Length
Average code length =
i=0,n (length*frequency)/ i=0,n frequency
= { 1(4) + 2(2) + 3(2) + 3(1) } /(4+2+2+1)
= 17 / 9 = 1.89
13
ENTROPY
Entropy = - i=1,n (pi log2 pi)
( p - probability of the symbol)
= - ( 0.44 * log20.44 + 0.22 * log20.22
+ 0.22 * log20.22 + 0.11 * log20.11 )
= - (0.44 * log0.44 + 2(0.22 * log0.22 + 0.11 * log0.11)
/ log2
= 1.8367
14
Entropy is a measure of information content:
the more probable the message, the lower its
information content, the lower its entropy
Advantages & Disadvantages
• The problem with Huffman coding is that it uses
an integral number of bits in each code.
• If the entropy of a given character is 2.5 bits,the
Huffman code for that character must be either 2
or 3 bits , not 2.5.
15
• Though Huffman coding is inefficient due to using
an integral number of bits per code , it is relatively
easy to implement and very efficient for coding
and decoding.
• It provides the best approximation for coding
symbols when using fixed width codes.
16

More Related Content

Similar to Module-IV 094.pdf

Computer-codes.pptx
Computer-codes.pptxComputer-codes.pptx
Computer-codes.pptx
PraveenThabbannavar
 
3F4ecc.ppt
3F4ecc.ppt3F4ecc.ppt
3F4ecc.ppt
Annymus
 
Data Communication & Computer network: Shanon fano coding
Data Communication & Computer network: Shanon fano codingData Communication & Computer network: Shanon fano coding
Data Communication & Computer network: Shanon fano coding
Dr Rajiv Srivastava
 
Data structures' project
Data structures' projectData structures' project
Data structures' project
Behappy Seehappy
 
Data communication & computer networking: Huffman algorithm
Data communication & computer networking:  Huffman algorithmData communication & computer networking:  Huffman algorithm
Data communication & computer networking: Huffman algorithm
Dr Rajiv Srivastava
 
Module-IV 093.pdf
Module-IV 093.pdfModule-IV 093.pdf
Module-IV 093.pdf
SamrajECE
 
Lec32
Lec32Lec32
Lecture 02 lexical analysis
Lecture 02 lexical analysisLecture 02 lexical analysis
Lecture 02 lexical analysis
Iffat Anjum
 
Huffman codes
Huffman codesHuffman codes
Huffman codes
Nargis Ehsan
 
Binary and EC codes
Binary and EC codesBinary and EC codes
Binary and EC codes
Mahesh Singh Madai
 
Hufman coding basic
Hufman coding basicHufman coding basic
Hufman coding basic
radthees
 
Greedy Algorithms Huffman Coding.ppt
Greedy Algorithms  Huffman Coding.pptGreedy Algorithms  Huffman Coding.ppt
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
Lecture 3.pptx
Lecture 3.pptxLecture 3.pptx
Lecture 3.pptx
PhocasSebastian1
 
Lecture 3.pptx
Lecture 3.pptxLecture 3.pptx
Lecture 3.pptx
PhocasSebastian1
 
Lec5 Compression
Lec5 CompressionLec5 Compression
Lec5 Compression
anithabalaprabhu
 
Huffman > Data Structures & Algorithums
Huffman > Data Structures & AlgorithumsHuffman > Data Structures & Algorithums
Huffman > Data Structures & Algorithums
Ain-ul-Moiz Khawaja
 
Module 2
Module 2 Module 2
Module 2
ShwetaNirmanik
 
SS & CD Module 3
SS & CD Module 3 SS & CD Module 3
SS & CD Module 3
ShwetaNirmanik
 
Arithmetic Coding
Arithmetic CodingArithmetic Coding
Arithmetic Coding
anithabalaprabhu
 
Huffman tree coding
Huffman tree codingHuffman tree coding

Similar to Module-IV 094.pdf (20)

Computer-codes.pptx
Computer-codes.pptxComputer-codes.pptx
Computer-codes.pptx
 
3F4ecc.ppt
3F4ecc.ppt3F4ecc.ppt
3F4ecc.ppt
 
Data Communication & Computer network: Shanon fano coding
Data Communication & Computer network: Shanon fano codingData Communication & Computer network: Shanon fano coding
Data Communication & Computer network: Shanon fano coding
 
Data structures' project
Data structures' projectData structures' project
Data structures' project
 
Data communication & computer networking: Huffman algorithm
Data communication & computer networking:  Huffman algorithmData communication & computer networking:  Huffman algorithm
Data communication & computer networking: Huffman algorithm
 
Module-IV 093.pdf
Module-IV 093.pdfModule-IV 093.pdf
Module-IV 093.pdf
 
Lec32
Lec32Lec32
Lec32
 
Lecture 02 lexical analysis
Lecture 02 lexical analysisLecture 02 lexical analysis
Lecture 02 lexical analysis
 
Huffman codes
Huffman codesHuffman codes
Huffman codes
 
Binary and EC codes
Binary and EC codesBinary and EC codes
Binary and EC codes
 
Hufman coding basic
Hufman coding basicHufman coding basic
Hufman coding basic
 
Greedy Algorithms Huffman Coding.ppt
Greedy Algorithms  Huffman Coding.pptGreedy Algorithms  Huffman Coding.ppt
Greedy Algorithms Huffman Coding.ppt
 
Lecture 3.pptx
Lecture 3.pptxLecture 3.pptx
Lecture 3.pptx
 
Lecture 3.pptx
Lecture 3.pptxLecture 3.pptx
Lecture 3.pptx
 
Lec5 Compression
Lec5 CompressionLec5 Compression
Lec5 Compression
 
Huffman > Data Structures & Algorithums
Huffman > Data Structures & AlgorithumsHuffman > Data Structures & Algorithums
Huffman > Data Structures & Algorithums
 
Module 2
Module 2 Module 2
Module 2
 
SS & CD Module 3
SS & CD Module 3 SS & CD Module 3
SS & CD Module 3
 
Arithmetic Coding
Arithmetic CodingArithmetic Coding
Arithmetic Coding
 
Huffman tree coding
Huffman tree codingHuffman tree coding
Huffman tree coding
 

More from SamrajECE

Unit 4 -IOT3_IoT_platform_Design_methodology.pptx
Unit 4 -IOT3_IoT_platform_Design_methodology.pptxUnit 4 -IOT3_IoT_platform_Design_methodology.pptx
Unit 4 -IOT3_IoT_platform_Design_methodology.pptx
SamrajECE
 
reservation-policy-required-followed for admission
reservation-policy-required-followed for admissionreservation-policy-required-followed for admission
reservation-policy-required-followed for admission
SamrajECE
 
M4L12.ppt
M4L12.pptM4L12.ppt
M4L12.ppt
SamrajECE
 
Module-V 096.pdf
Module-V 096.pdfModule-V 096.pdf
Module-V 096.pdf
SamrajECE
 
Module-IV 095.pdf
Module-IV 095.pdfModule-IV 095.pdf
Module-IV 095.pdf
SamrajECE
 
ModuleII092.pdf
ModuleII092.pdfModuleII092.pdf
ModuleII092.pdf
SamrajECE
 
ModuleII091.pdf
ModuleII091.pdfModuleII091.pdf
ModuleII091.pdf
SamrajECE
 
ModuleII090.pdf
ModuleII090.pdfModuleII090.pdf
ModuleII090.pdf
SamrajECE
 

More from SamrajECE (8)

Unit 4 -IOT3_IoT_platform_Design_methodology.pptx
Unit 4 -IOT3_IoT_platform_Design_methodology.pptxUnit 4 -IOT3_IoT_platform_Design_methodology.pptx
Unit 4 -IOT3_IoT_platform_Design_methodology.pptx
 
reservation-policy-required-followed for admission
reservation-policy-required-followed for admissionreservation-policy-required-followed for admission
reservation-policy-required-followed for admission
 
M4L12.ppt
M4L12.pptM4L12.ppt
M4L12.ppt
 
Module-V 096.pdf
Module-V 096.pdfModule-V 096.pdf
Module-V 096.pdf
 
Module-IV 095.pdf
Module-IV 095.pdfModule-IV 095.pdf
Module-IV 095.pdf
 
ModuleII092.pdf
ModuleII092.pdfModuleII092.pdf
ModuleII092.pdf
 
ModuleII091.pdf
ModuleII091.pdfModuleII091.pdf
ModuleII091.pdf
 
ModuleII090.pdf
ModuleII090.pdfModuleII090.pdf
ModuleII090.pdf
 

Recently uploaded

How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 

Recently uploaded (20)

How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 

Module-IV 094.pdf

  • 3. Huffman Coding • Huffman coding is a popular compression technique that assigns variable length codes (VLC) to symbols, so that the most frequently occurring symbols have the shortest codes. • On decompression the symbols are reassigned their original fixed length codes. 3
  • 4. • The idea is to use short bit strings to represent the most frequently used characters • and to use longer bit strings to represent less frequently used characters. 4
  • 5. • That is, the most common characters, usually space, e, and t are assigned the shortest codes. • In this way the total number of bits required to transmit the data can be considerably less than the number required if the fixed length ASCII representation is used. • A Huffman code is a binary tree with branches assigned the value 0 or 1. 5
  • 6. 6
  • 7. Huffman Algorithm • To each character, associate a binary tree consisting of just one node. • To each tree, assign the character’s frequency, which is called the tree’s weight. • Look for the two lightest-weight trees. If there are more than two, choose among them randomly. 7
  • 8. • Merge the two into a single tree with a new root node whose left and right sub trees are the two we chose. • Assign the sum of weights of the merged trees as the weight of the new tree. • Repeat the previous step until just one tree is left. 8
  • 9. Huffman Coding Example • Character frequencies – A: 20% (.20) – B: 9% (.09) – C: 15% – D: 11% – E: 40% – F: 5% • No other characters in the document 9
  • 11. Huffman Code • Codes – A: 010 – B: 0000 – C: 011 – D: 001 – E: 1 – F: 0001 • Note – None are prefixes of another 11 ABCDEF 1.0 E .4 C .15 A .20 D .11 F .05 BF .14 AC .35 BFD .25 ABCDF .6 B .09 0 0 0 0 0 1 1 1 1 1
  • 12. Huffman Coding • TENNESSEE 9 0/ 1 5 e(4) 0/ 1 s(2) 3 0/ 1 t(1) n(2) • ENCODING • E : 1 • S : 00 • T : 010 • N : 011 Average code length = (1*4 + 2*2 + 3*2 + 3*1) / 9 = 1.89 12
  • 13. Average Code Length Average code length = i=0,n (length*frequency)/ i=0,n frequency = { 1(4) + 2(2) + 3(2) + 3(1) } /(4+2+2+1) = 17 / 9 = 1.89 13
  • 14. ENTROPY Entropy = - i=1,n (pi log2 pi) ( p - probability of the symbol) = - ( 0.44 * log20.44 + 0.22 * log20.22 + 0.22 * log20.22 + 0.11 * log20.11 ) = - (0.44 * log0.44 + 2(0.22 * log0.22 + 0.11 * log0.11) / log2 = 1.8367 14 Entropy is a measure of information content: the more probable the message, the lower its information content, the lower its entropy
  • 15. Advantages & Disadvantages • The problem with Huffman coding is that it uses an integral number of bits in each code. • If the entropy of a given character is 2.5 bits,the Huffman code for that character must be either 2 or 3 bits , not 2.5. 15
  • 16. • Though Huffman coding is inefficient due to using an integral number of bits per code , it is relatively easy to implement and very efficient for coding and decoding. • It provides the best approximation for coding symbols when using fixed width codes. 16