Lecture 7: Run-Length, Golomb, and Tunstall...
Transcript of Lecture 7: Run-Length, Golomb, and Tunstall...
![Page 1: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/1.jpg)
Lecture 7:Run-Length, Golomb, and
Tunstall Codes
Thinh NguyenOregon State University
![Page 2: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/2.jpg)
Outline
Run-Length CodingGolomb CodingTunstall Coding
![Page 3: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/3.jpg)
Lossless coding: Run-Length encoding (RLE)
Redundancy is removed by not transmitting consecutive identical symbols (pixels or character values that are equal).
The repeated value can be coded once, along with the number of times it repeats.
Useful for coding black and white images e.g. fax.
![Page 4: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/4.jpg)
Binary RLECode the run length of 0’s using k bits. Transmit the code.Do not transmit runs of 1’s.Two consecutive 1’s are implicitly separately by a zero-length run of zero.
Example: suppose we use k = 4 bits to encode the run length (maximum run length of 15) for following bit patterns
![Page 5: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/5.jpg)
RLE Performance
Worst case behavior: transition occurs on each bit. Since we use k bits to represent the transition, we waste k-1 bits.
Best case behavior: no transition and use k bits to represent run length then the compression ratio is (2k-1)/k.
![Page 6: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/6.jpg)
Can you improve RLE coding?
Why use fixed length coding for the length of a run?
![Page 7: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/7.jpg)
Golomb CodingHow to code a potential infinite number of symbols?
Code the number of consecutive heads in a sequence of coin tosses.110, 1111110, 11111110, ….
![Page 8: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/8.jpg)
Golomb Coding
![Page 9: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/9.jpg)
Example
![Page 10: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/10.jpg)
Another Way of Looking at GolombCode (m=5)
![Page 11: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/11.jpg)
Run-Length Example, m = 5
![Page 12: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/12.jpg)
Choosing m
![Page 13: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/13.jpg)
Compression of Golomb Code
![Page 14: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/14.jpg)
GC Performance
![Page 15: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/15.jpg)
Notes on GC Useful for binary compression when one symbol is much more likely than another.
binary imagesfax documentsbit planes for wavelet image compression
Need a parameter (the order)trainingadaptively learn the right parameter
Variable-to-variable length code
Last symbol needs to be a 1coder always adds a 1decoder always removes a 1
![Page 16: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/16.jpg)
Tunstall Code
![Page 17: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/17.jpg)
Tunstall Code PropertiesNo input code is a prefix of another to assure unique encodability.
Minimize the number of bits per symbol.
![Page 18: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/18.jpg)
Prefix Code Properties
![Page 19: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/19.jpg)
Prefix Code Properties
Consider the string “cc”. It does not have a code.
Send the unused code and some fixed code for the cc.
Generally, if there are k internal nodes in the prefix tree then there is a need for k-1 fixed codes.
![Page 20: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/20.jpg)
Designing Tunstall Code
![Page 21: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/21.jpg)
Example
![Page 22: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/22.jpg)
Example
![Page 23: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/23.jpg)
Example
![Page 24: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/24.jpg)
Compression of Tunstall Code
![Page 25: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/25.jpg)
Average Bit Rate of Tunstall Code
![Page 26: Lecture 7: Run-Length, Golomb, and Tunstall Codesweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring... · 2006. 5. 9. · Code the run length of 0’s using k bits. Transmit](https://reader035.fdocuments.us/reader035/viewer/2022071516/61389f230ad5d20676495e50/html5/thumbnails/26.jpg)
Notes on Tunstall CodeVariable-to-fixed length code
Error resilient
A flipped bit will introduce just one error in the output.Huffman is not error resilient. A single bit flip can destroy the code.