Image Processing Architecture, © 2001-2004 Oleh TretiakPage 1Lecture 2 ECE-C490 Winter 2004 Image Processing Architecture Lecture 2, 1/8/2004 Lossless.

Slides:



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

Data Compression CS 147 Minh Nguyen.
Lecture 4 (week 2) Source Coding and Compression
Applied Algorithmics - week7
Sampling and Pulse Code Modulation
Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
Huffman code and ID3 Prof. Sin-Min Lee Department of Computer Science.
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.
SIMS-201 Compressing Information. 2  Overview Chapter 7: Compression Introduction Entropy Huffman coding Universal coding.
Chapter 6 Information Theory
Data Compression Michael J. Watts
Lecture04 Data Compression.
Compression & Huffman Codes
School of Computing Science Simon Fraser University
Lecture 6: Huffman Code Thinh Nguyen Oregon State University.
2015/6/15VLC 2006 PART 1 Introduction on Video Coding StandardsVLC 2006 PART 1 Variable Length Coding  Information entropy  Huffman code vs. arithmetic.
Spatial and Temporal Data Mining
SWE 423: Multimedia Systems Chapter 7: Data Compression (2)
DL Compression – Beeri/Feitelson1 Compression דחיסה Introduction Information theory Text compression IL compression.
Fundamentals of Multimedia Chapter 7 Lossless Compression Algorithms Ze-Nian Li and Mark S. Drew 건국대학교 인터넷미디어공학부 임 창 훈.
2015/7/12VLC 2008 PART 1 Introduction on Video Coding StandardsVLC 2008 PART 1 Variable Length Coding  Information entropy  Huffman code vs. arithmetic.
Lossless Compression - I Hao Jiang Computer Science Department Sept. 13, 2007.
EEE377 Lecture Notes1 EEE436 DIGITAL COMMUNICATION Coding En. Mohd Nazri Mahmud MPhil (Cambridge, UK) BEng (Essex, UK) Room 2.14.
Source Coding Hafiz Malik Dept. of Electrical & Computer Engineering The University of Michigan-Dearborn
1 Lossless Compression Multimedia Systems (Module 2) r Lesson 1: m Minimum Redundancy Coding based on Information Theory: Shannon-Fano Coding Huffman Coding.
Lossy Compression Based on spatial redundancy Measure of spatial redundancy: 2D covariance Cov X (i,j)=  2 e -  (i*i+j*j) Vertical correlation   
Basics of Compression Goals: to understand how image/audio/video signals are compressed to save storage and increase transmission efficiency to understand.
Huffman Coding Vida Movahedi October Contents A simple example Definitions Huffman Coding Algorithm Image Compression.
8. Compression. 2 Video and Audio Compression Video and Audio files are very large. Unless we develop and maintain very high bandwidth networks (Gigabytes.
Noiseless Coding. Introduction Noiseless Coding Compression without distortion Basic Concept Symbols with lower probabilities are represented by the binary.
15-853Page :Algorithms in the Real World Data Compression II Arithmetic Coding – Integer implementation Applications of Probability Coding – Run.
296.3Page 1 CPS 296.3:Algorithms in the Real World Data Compression: Lecture 2.5.
CS Spring 2011 CS 414 – Multimedia Systems Design Lecture 7 – Basics of Compression (Part 2) Klara Nahrstedt Spring 2011.
Image Processing and Computer Vision: 91. Image and Video Coding Compressing data to a smaller volume without losing (too much) information.
1 Classification of Compression Methods. 2 Data Compression  A means of reducing the size of blocks of data by removing  Unused material: e.g.) silence.
Lossless Compression CIS 465 Multimedia. Compression Compression: the process of coding that will effectively reduce the total number of bits needed to.
COMPRESSION. Compression in General: Why Compress? So Many Bits, So Little Time (Space) CD audio rate: 2 * 2 * 8 * = 1,411,200 bps CD audio storage:
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 8. Greedy Algorithms.
Image Processing Architecture, © Oleh TretiakPage 1Lecture 3 ECE-C490 Winter 2004 Image Processing Architecture Lecture 3, 1/13/2004 Lossless.
Huffman Code and Data Decomposition Pranav Shah CS157B.
Data Compression Meeting October 25, 2002 Arithmetic Coding.
Source Coding Efficient Data Representation A.J. Han Vinck.
Lecture 4: Lossless Compression(1) Hongli Luo Fall 2011.
CS654: Digital Image Analysis Lecture 34: Different Coding Techniques.
Lossless Compression(2)
STATISTIC & INFORMATION THEORY (CSNB134) MODULE 11 COMPRESSION.
1 Source Coding and Compression Dr.-Ing. Khaled Shawky Hassan Room: C3-222, ext: 1204, Lecture 7 (W5)
ELE 488 F06 ELE 488 Fall 2006 Image Processing and Transmission ( ) Image Compression Review of Basics Huffman coding run length coding Quantization.
Image Processing Architecture, © Oleh TretiakPage 1Lecture 4 ECE-C490 Winter 2004 Image Processing Architecture Lecture 4, 1/20/2004 Principles.
Multi-media Data compression
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.
CS Spring 2012 CS 414 – Multimedia Systems Design Lecture 7 – Basics of Compression (Part 2) Klara Nahrstedt Spring 2012.
Image Processing Architecture, © Oleh TretiakPage 1Lecture 7 ECEC 453 Image Processing Architecture Lecture 8, February 5, 2004 JPEG: A Standard.
Huffman Coding (2 nd Method). Huffman coding (2 nd Method)  The Huffman code is a source code. Here word length of the code word approaches the fundamental.
Lossless Compression-Statistical Model Lossless Compression One important to note about entropy is that, unlike the thermodynamic measure of entropy,
UNIT I. Entropy and Uncertainty Entropy is the irreducible complexity below which a signal cannot be compressed. Entropy is the irreducible complexity.
Image Processing Architecture, © Oleh TretiakPage 1Lecture 5 ECEC 453 Image Processing Architecture Lecture 5, 1/22/2004 Rate-Distortion Theory,
Submitted To-: Submitted By-: Mrs.Sushma Rani (HOD) Aashish Kr. Goyal (IT-7th) Deepak Soni (IT-8 th )
Information theory Data compression perspective Pasi Fränti
CSI-447: Multimedia Systems
Data Compression.
Algorithms in the Real World
Data Compression.
Data Compression CS 147 Minh Nguyen.
Context-based Data Compression
Why Compress? To reduce the volume of data to be transmitted (text, fax, images) To reduce the bandwidth required for transmission and to reduce storage.
CSE 589 Applied Algorithms Spring 1999
CSE 589 Applied Algorithms Spring 1999
Presentation transcript:

Image Processing Architecture, © Oleh TretiakPage 1Lecture 2 ECE-C490 Winter 2004 Image Processing Architecture Lecture 2, 1/8/2004 Lossless Coding (More) Oleh Tretiak Drexel University

Image Processing Architecture, © Oleh TretiakPage 2Lecture 2 Review: Need for Compression Example: Fax document - 8.5x11”, 200 dpi, 8.5x11x(200) 2 = 3.74 Mbits kbits/sec, /28800 = 130 sec - Typical compression = 15, with compression 8.65 sec. Example: Video - 640x480 pictures, 24 bits/sample, 30 frames/sec - 640x480x24x30 = 2.21E+08 bits/sec = 2.76E+07bytes/sec - A CD-ROM stores 650 Mbytes -> playing time = 650/27.6 = 23.5 sec - With compression, 74 minutes of low (VHS) quality video can be stored on a CD-ROM

Image Processing Architecture, © Oleh TretiakPage 3Lecture 2 Review: How is Compression Possible? Statistical Redundancy - Adjacent pixels are similar (spatial correlation) - Color components are similar (spectral correlation) - Successive frames are similar (temporal correlation) Perceptual Redundancy - Data can be eliminated from signal with no visible changes. Lossy compression: - Send (inferior) picture that requires fever bits.

Image Processing Architecture, © Oleh TretiakPage 4Lecture 2 Example: Compression We have 1000 symbols from alphabet {a b c d} Coding: 2 bits per symbol, total bits = 2x1000 = 2000 Variable length coding, some symbols are more frequent Total bits = = 1150 Average bits/symbol = 1150/1000 = 1.15 < 2 Compression = source bits/code bits = 2/1.15 =1.74

Image Processing Architecture, © Oleh TretiakPage 5Lecture 2 Review: Typical Encoder System Issues - Constant Bit Rate vs. Variable Bit Rate oIn lossless encoder, bit rate depends on compression efficiency oVariable bit rate is undesirable in real-time applications oIn lossy encoder, bit rate can be kept constant by varying quality - Single or Multiple Sample encoding oMultiple sample encoding is usually more efficient but also is more complex.

Image Processing Architecture, © Oleh TretiakPage 6Lecture 2 Review: Information Theory Let the i-th symbol have probability p i. The information of this symbol is defined as log 2 (1/ p i ) bits. The average information of this symbol is p i log 2 (1/ p i ) bits. The entropy of this symbol set is defined as Shannon Coding Theorem: It is possible to encode a (long) sequence of symbols with H +  bits per symbol How to do it? If the symbols are statistically independent, it is impossible to encode these with fewer than H bits per symbol. bits

Image Processing Architecture, © Oleh TretiakPage 7Lecture 2 Review: Entropy and Huffman Codes Theory - Information - Entropy - Shannon Compression Theorem Practice - Deriving symbols from signals - Huffman encoding oCoder construction oEncoders oDecoders

Image Processing Architecture, © Oleh TretiakPage 8Lecture 2 Review: Variable Length Codes Symbol set: s i, i = 1 … N, p i — symbol probability Code: c i, l i, where c i is a sequence of 1’s and 0’s of length l i. The code words must be decodable: the transmitted bit stream is just a set of 1’s and 0’s, code word boundaries are not indicated. For a decodable code, the code word boundaries can be found uniquely from the transmitted sequence. Sufficient condition for decodability: A code is decodable if no code word is at the beginning (prefix) of another code word. This is called the prefix condition Average code word length: For a decodable code, L ave ≥ H

Image Processing Architecture, © Oleh TretiakPage 9Lecture 2 This Lecture Huffman codes - How to construct codes - Encoding and decoding algorithms - Huffman codes with constrained length Golomb and Rice coding Arithmetic Coding - Coding when H < 1

Image Processing Architecture, © Oleh TretiakPage 10Lecture 2 Construction of a Huffman Code Tree construction - Order the symbols according to probabilities - Apply contraction process to the two symbols with lowest probability oassign a new (hypothetical) symbol to these two,with probabilities equal to sum of the code word probabilities - Repeat until one symbol is left Code construction - For the two initial branches of the tree, attach bit ‘0’ and ‘1’ at end of code word. - For both branches oIf (branch is a source symbol) done oelse repeat above process

Image Processing Architecture, © Oleh TretiakPage 11Lecture 2 Code construction example A=k,w B=u,A C=B,? D=l,r E=e,C H = 2.55

Image Processing Architecture, © Oleh TretiakPage 12Lecture 2 Variable Length Code: Encoding Source sequence: werule?

Image Processing Architecture, © Oleh TretiakPage 13Lecture 2 Prefix code: bit-serial decoding Algorithm steps: bold denotes output symbols - ECBAwEeDrECBuDl...

Image Processing Architecture, © Oleh TretiakPage 14Lecture 2 Prefix code: table decoding Let k be the maximum code symbol length. Construct table with 2 k entries. Each table location contains input symbol and code word length. Order code by binary value. A code symbol of length l will have 2 k-l entries. Since k = 5, we use 32 table entries. Code symbol ‘00’ will use =8 entries. Each entry will have output symbol ‘r’ and length 2. The next 8 entries will be for ‘l’. The following 8 entries will be for ‘e’. The following 4 entries will be for ‘?’, etc. Decoding:Take k = 5 bits from encoded sequence. Decode it by table lookup. From table, find the symbol length, discard these many bits from the code word used for lookup, take additional bits from encoded sequence.

Image Processing Architecture, © Oleh TretiakPage 15Lecture 2 Lookup table decoding example First lookup code: Output = ‘w’, l = 5, read 5 bits from input stream. Lookup code: Output = ‘e’, l = 2, discard the initial ‘10’ from lookup code, read two more bits Lookup code Output = ‘r’, l = 2, discard the initial ‘00’ from lookup code, read two more bits. Lookup code Output = ‘u’, l = 4, discard initial ‘1100’, read 4 more bits Lookup code Output = ‘l’,...

Image Processing Architecture, © Oleh TretiakPage 16Lecture 2 Huffman Codes With Constrained Length Some codes used in practice can have longest code words 20 bits long: huge lookup tables for lookup sequences Solution concept 1: ‘Escape’ sequences Solution concept 2: limit max code word length

Image Processing Architecture, © Oleh TretiakPage 17Lecture 2 Code construction - Escape Escape sequence approach - High probability code symbols decoded with lookup table, table is modest in size. - All low probability codes are lumped together: they are assigned one symbol (escape symbol) in the high probability table. - To encode low probability symbol, send escape symbol plus low- probability sequence (this will be another Huffman code). - Decoding: use high probability table: if escape symbol is encountered, switch to low probability table. This approach uses a hierarchical set of lookup tables for decoding

Image Processing Architecture, © Oleh TretiakPage 18Lecture 2 Rule of Thumb If symbol has probability p, then the length of a VLC code word should be about l = -log 2 p Examples - p = 0.5, l = 1 bit - p = 0.1, l = 3 bits - p = 0.01, l = 7 bit

Image Processing Architecture, © Oleh TretiakPage 19Lecture 2 Two level hierarchy: method S is the source, L be the maximum code word length Sort the symbols by probability, so that p 1 ≥ p 2 … ≥ p N Split the source into two sets: Create a special symbol Q with probability Augment S 1 by Q to form new set W. Design Huffman code for this this set Encoding: For symbols is S 1, output code word. For symbols in S 2, send Q, then symbol without encoding (this requires bits).

Image Processing Architecture, © Oleh TretiakPage 20Lecture 2 Example H = 2.65, L ave = 2.69 Max l is 9, decoding table requires 512 entries Target max length 5, min p > 1/2^5 = 1/32 = S 1 = (a, b, c, d, e), S 2 = (f … p) P(S 2 ) = , min p in S 1 = Both are greater than 1/32 Expect longest code word should be 5 bits or less

Image Processing Architecture, © Oleh TretiakPage 21Lecture 2 Example - Continued Build Huffman code for a-f + S 2 If a-f needs encoding, send code word If g-p needs encoding, send code for S 2, followed by binary number (one of 10) -> 4 bits Example: encode “cam”

Image Processing Architecture, © Oleh TretiakPage 22Lecture 2 Performance Analysis What is L ave ? L ave = Avg no of bits to send VLC + p(S 2 )*4 = *4 = How does this compare with Huffman code? For Huffman code, L ave = Other ideas?

Image Processing Architecture, © Oleh TretiakPage 23Lecture 2 Constrained Length - 2nd method Long code words produced by low probability symbols - Idea: modify probabilities, increasing the low probability values - Design Huffman code for this This approach produces codes with lower maximum length, but larger average length Leads to simpler encoder and decoder structure than escape (hierarchical) approach, but performance may not be as good.

Image Processing Architecture, © Oleh TretiakPage 24Lecture 2 Golomb-Rice coding Golomb: P(n) = (1 – p 0 )p 0 n, n ≥ 0 (geometric distribution) - Let - Given n, compute quotient and remainder for n =mq + r. - Codeword is unary code for m (m zeroes followed by a 1), followed by the binary code for r. - Golomb-Rice: special case when m = 2 k (only case used in practice). Example: m = 4, n = 13 = 4* q = 3, r = 1. Code for q = 0001, code for r = 01, full code word is This distribution is of much practical use!

Image Processing Architecture, © Oleh TretiakPage 25Lecture 2 Huffman vs. Arithmetic Code Lowest L ave for Huffman codes is 1. Suppose H << 1? - One option: use one code symbol for several source symbols - Another option: Arithmetic code. Idea behind arithmetic code: - Represent the probability of a sequence by a binary number.

Image Processing Architecture, © Oleh TretiakPage 26Lecture 2 Arithmetic Encoding Assume source alphabet has values 0 and 1, p 0 = p, p 1 = 1 – p. A sequence of symbols s 1, s 2, … s m is represented by a probability interval found as follows: - Initialize, lo = 0; hi = 1 - For i = 0 to m oif s i = 0 § hi = lo + (lo-hi)* p 0 oelse § lo = lo + (lo-hi)* p 0 oend - end Send binary fraction x such that lo ≤ x < hi. This will require

Image Processing Architecture, © Oleh TretiakPage 27Lecture 2 Arithmetic Encoding Assume source alphabet has values 0 and 1, p 0 = p, p 1 = 1 – p. A sequence of symbols s 1, s 2, … s m is represented by a probability interval found as follows: - Initialize, lo = 0; range = 1 - For i = 0 to m oif s i = 0 § range = range*p oelse // s i = 1 § lo = lo + range*p § range = range*(1-p) oend - end Send binary fraction x such that lo ≤ x < hi. This will require

Image Processing Architecture, © Oleh TretiakPage 28Lecture 2 Arithmetic coding: example p 0 = 0.2, source sequence is 1101 Number of bits = ceiling(-log 2 (0.1024)) = 4 Bits sent: (1-0.36)*0.2 = (1-0)*0.2 = 0.2

Image Processing Architecture, © Oleh TretiakPage 29Lecture 2 Arithmetic coding: example p 0 = 0.2, source sequence is 1101 Number of bits = ceiling(-log 2 (0.1024)) = 4 low 2 = , (low+range) 2 = Bits sent: 0111

Image Processing Architecture, © Oleh TretiakPage 30Lecture 2 Arithmetic Decoding We receive x, a binary fraction lo = 0; hi = 1 for i = 1 to m - if (x - lo) < p*(hi-lo) osi = 0 ohi = lo + (hi-lo)*p - else osi = 1 olo = lo + (hi-lo)*p - end end

Image Processing Architecture, © Oleh TretiakPage 31Lecture 2 Arithmetic Decoding We receive x, a binary fraction lo = 0; range = 1; for i = 1 to m - if (x - lo) < p*range osi = 0 orange = p*range - else osi = 1 olo = lo +range*p orange = range*(1 - p) - end end

Image Processing Architecture, © Oleh TretiakPage 32Lecture 2 Arithmetic Decoding We receive x, a binary fraction for i = 1 to m - if x < p osi = 0 ox = x/p - Else // x > p osi = 1 ox = (x - p)/(1 - p) - end end Receive x = 0111 = p = 0.2

Image Processing Architecture, © Oleh TretiakPage 33Lecture 2 Arithmetic decoding example Receive 0111 (0.4375), decode 4 bits, p0 = 0.2

Image Processing Architecture, © Oleh TretiakPage 34Lecture 2 Arithmetic decoding example Receive 0111 (0.4375), decode 4 bits, p0 = 0.2

Image Processing Architecture, © Oleh TretiakPage 35Lecture 2 Magic Features of Arithmetic Coding Remember I (information) = - log 2 p - p = 0.5, I = 1 - p = 0.125, I = 3 - p = 0.99, I = 0,0145 (wow!) High p symbol, less than 1 code bit per symbol! In encoder, hi - lo = ∑ I(symbols)

Image Processing Architecture, © Oleh TretiakPage 36Lecture 2 Summary: Arithmetic Coding Complexity: requires arithmetic (multiplications, divisions), rather than just table lookups Algorithms are complex, accuracy (significant bits) is tricky Can be made to operate incrementally - Both encoder and decoder can output symbols with limited internal memory Provides important compression savings in certain settings Part of standards

Image Processing Architecture, © Oleh TretiakPage 37Lecture 2 Summary: VLC Lowest level (basis) of image compression We talked about - Huffman - Golomb/Rice - Arithmetic Two phases - Code design - Encoding/decoding More about VLC - Adaptive coding: estimate probabilities - There are universal coders (good non-adaptive coding) such as Lempel-Ziv (zip)