Lossless Compression-Statistical Model Lossless Compression One important to note about entropy is that, unlike the thermodynamic measure of entropy,

Slides:



Advertisements
Similar presentations
Noise, Information Theory, and Entropy (cont.) CS414 – Spring 2007 By Karrie Karahalios, Roger Cheng, Brian Bailey.
Advertisements

Lecture 4 (week 2) Source Coding and Compression
Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
Greedy Algorithms Amihood Amir Bar-Ilan University.
Arithmetic Coding. Gabriele Monfardini - Corso di Basi di Dati Multimediali a.a How we can do better than Huffman? - I As we have seen, the.
Bounds on Code Length Theorem: Let l ∗ 1, l ∗ 2,..., l ∗ m be optimal codeword lengths for a source distribution p and a D-ary alphabet, and let L ∗ be.
Greedy Algorithms (Huffman Coding)
CPSC 335 Compression and Huffman Coding Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Data Compressor---Huffman Encoding and Decoding. Huffman Encoding Compression Typically, in files and messages, Each character requires 1 byte or 8 bits.
Lecture04 Data Compression.
School of Computing Science Simon Fraser University
Huffman Encoding 16-Apr-17.
1 Huffman Codes. 2 Introduction Huffman codes are a very effective technique for compressing data; savings of 20% to 90% are typical, depending on the.
Lecture 6: Huffman Code Thinh Nguyen Oregon State University.
CSc 461/561 CSc 461/561 Multimedia Systems Part B: 1. Lossless Compression.
A Data Compression Algorithm: Huffman Compression
Chapter 9: Huffman Codes
4.8 Huffman Codes These lecture slides are supplied by Mathijs de Weerd.
Lecture 4 Source Coding and Compression Dr.-Ing. Khaled Shawky Hassan
Fundamentals of Multimedia Chapter 7 Lossless Compression Algorithms Ze-Nian Li and Mark S. Drew 건국대학교 인터넷미디어공학부 임 창 훈.
Huffman Coding. Main properties : –Use variable-length code for encoding a source symbol. –Shorter codes are assigned to the most frequently used symbols,
Data Compression Basics & Huffman Coding
Data Compression and Huffman Trees (HW 4) Data Structures Fall 2008 Modified by Eugene Weinstein.
1 Lossless Compression Multimedia Systems (Module 2) r Lesson 1: m Minimum Redundancy Coding based on Information Theory: Shannon-Fano Coding Huffman Coding.
Huffman Codes Message consisting of five characters: a, b, c, d,e
Data Structures and Algorithms Huffman compression: An Application of Binary Trees and Priority Queues.
Noiseless Coding. Introduction Noiseless Coding Compression without distortion Basic Concept Symbols with lower probabilities are represented by the binary.
1 Lossless Compression Multimedia Systems (Module 2 Lesson 2) Summary:  Adaptive Coding  Adaptive Huffman Coding Sibling Property Update Algorithm 
Page 110/6/2015 CSE 40373/60373: Multimedia Systems So far  Audio (scalar values with time), image (2-D data) and video (2-D with time)  Higher fidelity.
CS-2852 Data Structures LECTURE 13B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
4.8 Huffman Codes These lecture slides are supplied by Mathijs de Weerd.
Multimedia Data Introduction to Lossless Data Compression Dr Sandra I. Woolley Electronic, Electrical.
Compression.  Compression ratio: how much is the size reduced?  Symmetric/asymmetric: time difference to compress, decompress?  Lossless; lossy: any.
1 Source Coding and Compression Dr.-Ing. Khaled Shawky Hassan Room: C3-222, ext: 1204, Lecture 5.
File Compression Techniques Alex Robertson. Outline History Lossless vs Lossy Basics Huffman Coding Getting Advanced Lossy Explained Limitations Future.
Lossless Compression CIS 465 Multimedia. Compression Compression: the process of coding that will effectively reduce the total number of bits needed to.
Huffman coding Content 1 Encoding and decoding messages Fixed-length coding Variable-length coding 2 Huffman coding.
Adaptive Huffman Coding. Gabriele Monfardini - Corso di Basi di Dati Multimediali a.a Why Adaptive Huffman Coding? Huffman coding suffers.
Abdullah Aldahami ( ) April 6,  Huffman Coding is a simple algorithm that generates a set of variable sized codes with the minimum average.
Huffman Codes Juan A. Rodriguez CS 326 5/13/2003.
CS654: Digital Image Analysis Lecture 34: Different Coding Techniques.
Huffman’s Algorithm 11/02/ Weighted 2-tree A weighted 2-tree T is an extended binary tree with n external nodes and each of the external nodes is.
Foundation of Computing Systems
Lossless Compression(2)
1 Source Coding and Compression Dr.-Ing. Khaled Shawky Hassan Room: C3-222, ext: 1204, Lecture 7 (W5)
ENTROPY & RUN LENGTH CODING. Contents What is Entropy coding? Huffman Encoding Huffman encoding Example Arithmetic coding Encoding Algorithms for arithmetic.
1 Data Compression Hae-sun Jung CS146 Dr. Sin-Min Lee Spring 2004.
Chapter 7 Lossless Compression Algorithms 7.1 Introduction 7.2 Basics of Information Theory 7.3 Run-Length Coding 7.4 Variable-Length Coding (VLC) 7.5.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Compression and Huffman Coding. Compression Reducing the memory required to store some information. Lossless compression vs lossy compression Lossless.
Lecture on Data Structures(Trees). Prepared by, Jesmin Akhter, Lecturer, IIT,JU 2 Properties of Heaps ◈ Heaps are binary trees that are ordered.
Design & Analysis of Algorithm Huffman Coding
Huffman Codes ASCII is a fixed length 7 bit code that uses the same number of bits to define each character regardless of how frequently it occurs. Huffman.
HUFFMAN CODES.
Data Coding Run Length Coding
Data Compression.
Proving the Correctness of Huffman’s Algorithm
Huffman Coding, Arithmetic Coding, and JBIG2
Optimal Merging Of Runs
Chapter 8 – Binary Search Tree
Chapter 9: Huffman Codes
Optimal Merging Of Runs
Chapter 11 Data Compression
Huffman Coding CSE 373 Data Structures.
Greedy: Huffman Codes Yin Tat Lee
Huffman Encoding.
CSE 589 Applied Algorithms Spring 1999
Proving the Correctness of Huffman’s Algorithm
Presentation transcript:

Lossless Compression-Statistical Model

Lossless Compression One important to note about entropy is that, unlike the thermodynamic measure of entropy, we can see no absolute number for the information content of a given message One important to note about entropy is that, unlike the thermodynamic measure of entropy, we can see no absolute number for the information content of a given message The probability figure we see is actually the probability for a given model that is kept inside the human brain. It is just a model, not an absolute number The probability figure we see is actually the probability for a given model that is kept inside the human brain. It is just a model, not an absolute number

Lossless Compression In order to compress data well,we need to select models that predict symbols with high probabilities In order to compress data well,we need to select models that predict symbols with high probabilities A symbol that has a high probability has low information content and will need fewer bits to encode A symbol that has a high probability has low information content and will need fewer bits to encode Lossless data compression is generally implemented using one of two different types of modeling Lossless data compression is generally implemented using one of two different types of modeling statistical or dictionary-based statistical or dictionary-based

Lossless Compression Statistical modeling reads in and encodes a single symbol at a time using the probability of that character ’ s appearance Statistical modeling reads in and encodes a single symbol at a time using the probability of that character ’ s appearance Huffman coding Huffman coding Shannon-Fano coding Shannon-Fano coding Arithmetic coding Arithmetic coding Dictionary-based modeling uses a single code to replace strings of symbols Dictionary-based modeling uses a single code to replace strings of symbols LZ77 LZ77 LZ78 LZ78 LZW LZW

Minimum Redundancy Coding Given the probabilities, a table of codes could be constructed that has several important properties Given the probabilities, a table of codes could be constructed that has several important properties Different codes have different number of bits Different codes have different number of bits Codes for symbols with low probabilities have more bits, and codes for symbols with high probabilities have fewer bits Codes for symbols with low probabilities have more bits, and codes for symbols with high probabilities have fewer bits

Shannon-Fano Algorithm Though the codes are of different bit lengths, they can be uniquely decodes Though the codes are of different bit lengths, they can be uniquely decodes For a given list of symbols, develop a corresponding list of probabilities or frequency counts For a given list of symbols, develop a corresponding list of probabilities or frequency counts Sort the lists of symbols in descending order Sort the lists of symbols in descending order Divide the list into two parts, such that the total frequency counts of the two parts are as close as possible. Divide the list into two parts, such that the total frequency counts of the two parts are as close as possible. Assign 0,1 to the upper, lower parts, respectively Assign 0,1 to the upper, lower parts, respectively Recursively apply the same procedure to each of the two halves until each symbol has become a leaf Recursively apply the same procedure to each of the two halves until each symbol has become a leaf

Shannon-Fano Algorithm Symbol Count Code A B7 0 1 D C6 1 0 E First division 2nd division 3rd division 4th division

Huffman Coding Huffman codes are built from the bottom up, starting with the leaves of the tree and working progressively closer to the root Huffman codes are built from the bottom up, starting with the leaves of the tree and working progressively closer to the root The two free nodes with the lowest weights are located The two free nodes with the lowest weights are located Create a parent node, whose weight is the sum of the two son nodes, for these two nodes Create a parent node, whose weight is the sum of the two son nodes, for these two nodes Let the newly created parent node be a free node and the two son nodes be removed from the list Let the newly created parent node be a free node and the two son nodes be removed from the list Assign 0,1 to the two son nodes paths, arbitrarily Assign 0,1 to the two son nodes paths, arbitrarily Repeat the Huffman Algorithm until only one free node is left Repeat the Huffman Algorithm until only one free node is left

Huffman Coding

Huffman coding will always at least equal the efficiency of Shannon-Fano coding, so it has become the predominate coding method of this type Huffman coding will always at least equal the efficiency of Shannon-Fano coding, so it has become the predominate coding method of this type It was shown that Huffman coding cannot be improved or with any other integral bit-width coding stream It was shown that Huffman coding cannot be improved or with any other integral bit-width coding stream JPEG, MPEG, and etc JPEG, MPEG, and etc

Adaptive Huffman Coding Adaptive coding lets us use higher-order modeling without paying any penalty for added statistics Adaptive coding lets us use higher-order modeling without paying any penalty for added statistics It does this by adjusting the Huffman tree on the fly, based on data previously seen and having no knowledge about future statistics It does this by adjusting the Huffman tree on the fly, based on data previously seen and having no knowledge about future statistics Sibling property Sibling property A tree is said to exhibit sibling property if the nodes can be listed in order of increasing weight and if every node appears adjacent to its sibling in the list A tree is said to exhibit sibling property if the nodes can be listed in order of increasing weight and if every node appears adjacent to its sibling in the list

Adaptive Huffman Coding A binary tree is a Huffman tree if and only if it obeys the sibling property A binary tree is a Huffman tree if and only if it obeys the sibling property

Adaptive Huffman Coding Thus, maintain the sibling property during the update assure that we have a Huffman tree before and after the counts are updated Thus, maintain the sibling property during the update assure that we have a Huffman tree before and after the counts are updated

Adaptive Huffman Coding

If the newly incremented node now has a weight of w+1, the next higher node will have a weight of w when updating is needed If the newly incremented node now has a weight of w+1, the next higher node will have a weight of w when updating is needed There may be more nodes after the next higher one that have a value of w as well. The update (swap) procedure moves up the node list till it finds the last node with a weight of w There may be more nodes after the next higher one that have a value of w as well. The update (swap) procedure moves up the node list till it finds the last node with a weight of w That node is swapped with the node with weight w+1 That node is swapped with the node with weight w+1

Adaptive Huffman Coding In this example, D is swapped with A In this example, D is swapped with A The next node to be incremented will be the new parent of the incremented node. In this example, it is node #6 The next node to be incremented will be the new parent of the incremented node. In this example, it is node #6 As each node is incremented, a check is performed for correct ordering. A swap is performed if necessary As each node is incremented, a check is performed for correct ordering. A swap is performed if necessary

Adaptive Huffman Coding

Not a Huffman tree

Adaptive Huffman Coding Still not a Huffman tree

Adaptive Huffman Coding Now, it is a Huffman tree again

Adaptive Huffman Coding Note that the code length for A changes from 3 to 2 Note that the code length for A changes from 3 to 2 And the code length for B and D changes from 3 to 4 And the code length for B and D changes from 3 to 4

Adaptive Huffman Coding Initialization Initialization Create a Huffman tree with two symbol EOF and ESCAPE with weight being 1 Create a Huffman tree with two symbol EOF and ESCAPE with weight being 1 Let C be the incoming character Let C be the incoming character If C is in the Huffman tree, then transmit the Huffman code for C and update the Huffman tree, else transmit the Huffman code for ESCAPE and the plain 8-bit character for C, and then update the Huffman tree for ESCAPE and C If C is in the Huffman tree, then transmit the Huffman code for C and update the Huffman tree, else transmit the Huffman code for ESCAPE and the plain 8-bit character for C, and then update the Huffman tree for ESCAPE and C

Adaptive Huffman Coding The overflow problem The overflow problem the weight of the root exceeds the capacity as the program progresses long enough the weight of the root exceeds the capacity as the program progresses long enough The longest possible Huffman code exceeds the range of the integer used as a stack The longest possible Huffman code exceeds the range of the integer used as a stack It is needed because the encoding and decoding phases treat the Huffman tree path in reverse order It is needed because the encoding and decoding phases treat the Huffman tree path in reverse order Solution Solution Recalling the weight by a factor of 1/2 Recalling the weight by a factor of 1/2 It can possibly reshape the tree It can possibly reshape the tree

Adaptive Huffman Coding Problems occur when divided by 2

Rebuilding the tree is sometimes needed

Arithmetic Coding Huffman coding has been proven the best fixed length coding method available Huffman coding has been proven the best fixed length coding method available Yet, since Huffman codes have to be an integral number of bits long, while the entropy value of a symbol may (as a matter of fact, almost always so) be a faction number, theoretical possible compressed message cannot be achieved Yet, since Huffman codes have to be an integral number of bits long, while the entropy value of a symbol may (as a matter of fact, almost always so) be a faction number, theoretical possible compressed message cannot be achieved

Arithmetic Coding For example, if a statistical method assign 90% probability to a given character, the optimal code size would be 0.15 bits For example, if a statistical method assign 90% probability to a given character, the optimal code size would be 0.15 bits The Huffman coding system would probably assign a 1-bit code to the symbol, which is six times longer than necessary The Huffman coding system would probably assign a 1-bit code to the symbol, which is six times longer than necessary Arithmetic coding bypasses the idea of replacing an input symbol with a specific code. It replaces a stream of input symbols with a single floating-point output number Arithmetic coding bypasses the idea of replacing an input symbol with a specific code. It replaces a stream of input symbols with a single floating-point output number

Character probability Range ^(space) 1/10 A 1/10 B 1/10 E 1/10 G 1/10 I 1/10 L 2/10 S 1/10 T 1/10 Suppose that we want to encode the message BILL GATES

Arithmetic Coding To encode the first character B properly, the final coded message has to be a number greater than or equal to 0.20 and less than 0.30 To encode the first character B properly, the final coded message has to be a number greater than or equal to 0.20 and less than 0.30 After the first character is encoded, the low end for the range is changed from 0.00 to 0.20 and the high end for the range is changed from 1.00 to 0.30 After the first character is encoded, the low end for the range is changed from 0.00 to 0.20 and the high end for the range is changed from 1.00 to 0.30 The next character to be encoded, the letter I, owns the range 0.50 to 0.60 in the new subrange of 0.20 to 0.30 The next character to be encoded, the letter I, owns the range 0.50 to 0.60 in the new subrange of 0.20 to 0.30 So, the new encoded number will fall somewhere in the 50th to 60th percentile of the currently established. So, the new encoded number will fall somewhere in the 50th to 60th percentile of the currently established. Thus, this number is further restricted to 0.25 to 0.26 Thus, this number is further restricted to 0.25 to 0.26

Arithmetic Coding Encoding algorithm for arithmetic coding Encoding algorithm for arithmetic coding Low = 0.0 ; high =1.0 ; while not EOF do range = high - low ; read(c) ; high = low + range  high_range(c) ; low = low + range  low_range(c) ; enddooutput(low);

Arithmetic Coding New character Low value high value B I L L ^(space) G A T E S

Arithmetic Coding Decoding is the inverse process Decoding is the inverse process Since falls between 0.2 and 0.3, the first character must be ‘ B ’ Since falls between 0.2 and 0.3, the first character must be ‘ B ’ Removing the effect of ‘ B ’ from by first subtracting the low value of B, 0.2, giving Removing the effect of ‘ B ’ from by first subtracting the low value of B, 0.2, giving Then divided by the width of the range of ‘ B ’, 0.1. This gives a value of Then divided by the width of the range of ‘ B ’, 0.1. This gives a value of

Arithmetic Coding Decoding algorithm Decoding algorithm r = input_code repeat search c such that r falls in its range ; search c such that r falls in its range ; output(c) ; output(c) ; r = r - low_range(c) ; r = r - low_range(c) ; r = r/(high_range(c) - low_range(c)); r = r/(high_range(c) - low_range(c)); until EOF or the length of the message is reached

r cLow High range B I L L ^(space) G A T E S

Arithmetic Coding In summary, the encoding process is simply one of narrowing the range of possible numbers with every new symbol In summary, the encoding process is simply one of narrowing the range of possible numbers with every new symbol The new range is proportional to the predefined probability attached to that symbol The new range is proportional to the predefined probability attached to that symbol Decoding is the inverse procedure, in which the range is expanded in proportion to the probability of each symbol as it is extracted Decoding is the inverse procedure, in which the range is expanded in proportion to the probability of each symbol as it is extracted