1 / 81

Lossy Compression

Lossy Compression. 15-211 Fundamental Data Structures and Algorithms. Peter Lee February 18, 2003. Announcements. Homework #4 is available Due on Monday, March 17, 11:59pm Get started now! Quiz #2 Available on Tuesday, Feb.25

rich
Download Presentation

Lossy Compression

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lossy Compression 15-211 Fundamental Data Structures and Algorithms Peter Lee February 18, 2003

  2. Announcements • Homework #4 is available • Due on Monday, March 17, 11:59pm • Get started now! • Quiz #2 • Available on Tuesday, Feb.25 • Some questions will be easier if you have some parts of HW4 working • Read • Chapter 8

  3. HW4 is out!

  4. Before we begin…

  5. Eliza • Eliza was one of the first AI programs • J. Weizenbaum, 1966 • At the time, it impressed people who used it • Eliza has been implemented many, many times • gnu emacs has one • try “M-x doctor”

  6. Eliza’s impact • Many stories of Eliza’s impact • some people became so dependent that Weizenbaum eventually had to withdraw its use • some psychiatrists saw Eliza as a way for the profession to handle many more patients • Eliza might be used for most patients, and the human doctor reserved for only the most serious cases

  7. Eliza’s rules • Eliza is a remarkably simple program • Some sample rules: • X me YX you Y • I remember X Why do you remember X just now? • My <family-member> is X Who else in your family is X? • X <family-member> Y Tell me more about your family • X  That is very interesting

  8. Why “Eliza”? • The name was chosen for its ability to converse increasingly well • The Greek legend of Pygmalion • the mysogynist King of Cyprus • fell in love with an ivory statue, Galatea • taking pity, Aphrodite made Galatea come alive • Pygmalion then married Galatea

  9. Why “Eliza”? – cont’d • George Bernard Shaw wrote a play, Pygmalion, based on the legend • Professor Higgins creates a “lady” from a low-class cockney flower vendor, Eliza Doolittle • first filmed in 1938 • Later, adapted into the “politically correct” My Fair Lady

  10. Wrap-Up on LZW Compression

  11. Byte method LZW • We start with a trie that contains a root and n children • one child for each possible character • each child labeled 0…n • When we compress as before, by walking down the trie • but, after emitting a code and growing the trie, we must start from the root’s child labeled c, where c is the character that caused us to grow the trie

  12. LZW: Byte method example • Suppose our entire character set consists only of the four letters: • {a, b, c, d} • Let’s consider the compression of the string • baddad

  13. Byte LZW: Compress example baddad Input: ^ Dictionary: b a c d 0 1 2 3 Output:

  14. Byte LZW: Compress example baddad Input: ^ Dictionary: b a c d 0 1 2 3 a 4 Output: 1

  15. Byte LZW: Compress example baddad Input: ^ Dictionary: b a c d 0 1 2 3 d a 5 4 Output: 10

  16. Byte LZW: Compress example baddad Input: ^ Dictionary: b a c d 0 1 2 3 d a d 5 4 6 Output: 103

  17. Byte LZW: Compress example baddad Input: ^ Dictionary: b a c d 0 1 2 3 a d a d 5 4 6 7 Output: 1033

  18. Byte LZW: Compress example baddad Input: ^ Dictionary: b a c d 0 1 2 3 a d a d 5 4 6 7 Output: 10335

  19. Byte LZW output • So, the input • baddad • compresses to • 10335 • which again can be given in bit form, just like in the binary method… • …or compressed again using Huffman

  20. Byte LZW: Uncompress example • The uncompress step for byte LZW is the most complicated part of the entire process, but is largely similar to the binary method

  21. Byte LZW: Uncompress example 10335 Input: ^ Dictionary: b a c d 0 1 2 3 Output:

  22. Byte LZW: Uncompress example 10335 Input: ^ Dictionary: b a c d 0 1 2 3 b Output:

  23. Byte LZW: Uncompress example 10335 Input: ^ Dictionary: b a c d 0 1 2 3 a 4 ba Output:

  24. Byte LZW: Uncompress example 10335 Input: ^ Dictionary: b a c d 0 1 2 3 d a 5 4 bad Output:

  25. Byte LZW: Uncompress example 10335 Input: ^ Dictionary: b a c d 0 1 2 3 d a d 5 4 6 badd Output:

  26. Byte LZW: Uncompress example 10335 Input: ^ Dictionary: b a c d 0 1 2 3 a d a d 5 4 6 7 baddad Output:

  27. LZW applications • LZW is an extremely useful lossless method for compressing data • LZW is used in the GIF and compressed TIFF standards for image data • Unisys holds the patent on LZW, but allows free noncommercial use

  28. Quiz Break

  29. LZW performance • Suppose we have a file of N a’s: • aaaa…a • What would the output look like after LZW compression? • What, roughly, is the size of the output (in big-Oh terms)? • How big would the output be if we used Huffman instead?

  30. Lossy Compression

  31. Lossy compression • Often, we can tolerate some loss of data through the compress/ decompress cycle. • Images, and especially video/audio, can be huge • HDTV bit rate is >1Gbps! • Big problem for storage and network

  32. Techniques • Lossy compression is based on mathematical transformations • Discrete Cosine Transform (DCT) • Used in JPEG algorithm • Wavelet based image compression • Used in MPEG-4 • Many, many, others…

  33. Image files One-dimensional array of 3  width  height bytes Three two-dimensional arrays, one for each color component

  34. Consider this color image This is part of a famous image (Do you know who? Hint: Splay) The image is a 16x16 bitmap image enlarged

  35. Here is the Red part of the image

  36. Green Part

  37. Blue Part

  38. The red image, again 173 165 165 165 148 132 123 132 140 156 173 181 181 181 189 173 198 189 189 189 181 165 148 165 165 173 181 198 206 198 181 165 206 206 206 206 198 189 181 181 198 206 206 222 231 214 181 165 231 222 206 198 189 181 181 181 206 222 222 222 231 222 198 181 231 214 189 173 165 165 173 181 181 189 198 222 239 231 206 214 206 189 173 148 148 148 148 165 156 148 165 198 222 231 214 239 181 165 140 123 123 115 115 123 140 148 140 148 165 206 239 247 165 82 66 82 90 82 90 107 123 123 115 132 140 165 198 231 123 198 74 49 57 82 82 99 107 115 115 123 132 132 148 214 239 239 107 82 82 74 90 107 123 115 115 123 115 115 123 198 255 90 74 74 99 74 115 123 132 123 123 115 115 140 165 189 247 99 99 82 90 107 123 123 123 123 123 132 140 156 181 198 247 239 165 132 107 148 140 132 132 123 132 148 140 140 156 214 198 231 165 156 132 156 156 140 140 140 148 148 132 140 156 222 247 239 222 181 181 140 156 140 148 148 148 140 132 156 206 222 214 198 181 181 181 181 173 148 156 148 140 140 165 198 222 239 Byte values (0…255) indicate intensity of the color at each pixel

  39. 173 165 165 165 148 132 123 132 140 156 173 181 181 181 189 173 198 189 189 189 181 165 148 165 165 173 181 198 206 198 181 165 206 206 206 206 198 189 181 181 198 206 206 222 231 214 181 165 231 222 206 198 189 181 181 181 206 222 222 222 231 222 198 181 231 214 189 173 165 165 173 181 181 189 198 222 239 231 206 214 206 189 173 148 148 148 148 165 156 148 165 198 222 231 214 239 181 165 140 123 123 115 115 123 140 148 140 148 165 206 239 247 165 82 66 82 90 82 90 107 123 123 115 132 140 165 198 231 123 198 74 49 57 82 82 99 107 115 115 123 132 132 148 214 239 239 107 82 82 74 90 107 123 115 115 123 115 115 123 198 255 90 74 74 99 74 115 123 132 123 123 115 115 140 165 189 247 99 99 82 90 107 123 123 123 123 123 132 140 156 181 198 247 239 165 132 107 148 140 132 132 123 132 148 140 140 156 214 198 231 165 156 132 156 156 140 140 140 148 148 132 140 156 222 247 239 222 181 181 140 156 140 148 148 148 140 132 156 206 222 214 198 181 181 181 181 173 148 156 148 140 140 165 198 222 239 The red image, again Byte values (0…255) indicate intensity of the color at each pixel

  40. JPEG

  41. JPEG • Joint Photographic Expert Group • Voted as international standard in 1992 • Works well for both color and grayscale images • Many steps in the algorithm • Some requiring sophistication in mathematics • We’ll skip many parts and focus on just the main elements of JPEG

  42. B G R Y I Q JPEG in a nutshell for each plane (scan) RGB to YIQ (optional) DPCM Zig-zag Quant DCT for each 8x8 block RLE 11010001… Huffman

  43. B G R Y I Q JPEG in a nutshell for each plane (scan) RGB to YIQ (optional) DPCM Zig-zag Quant DCT for each 8x8 block RLE 11010001… Huffman

  44. Linear transform coding • For video, audio, or images, one key first step of the compression will be to encode values over regions of time or space • The basic strategy is to select a set of linear basis functions i that span the space • sin, cos, wavelets, … • defined at discrete points

  45. Linear transform coding • Coefficients: • In matrix notation: • Where A is an nxn matrix, and each row defines a basis function

  46. Cosine transform

  47. Discrete Cosine Transform • DCT separates the image into spectral sub-bands of differing importance • With input image A, the output coefficients B are given by the following equation: N1 and N2 give the image’s height and width

  48. Basis functions

  49. B G R Y I Q JPEG in a nutshell for each plane (scan) RGB to YIQ (optional) DPCM Zig-zag Quant DCT for each 8x8 block RLE 11010001… Huffman

  50. Quantization • The purpose of quantization is to encode an entire region of values into a single value • For example, can simply delete low-order bits: • 101101 could be encoded as 1011 or 101 • When dividing by power-of-two, this amounts to deleting whole bits • Other division constants give finer control over bit loss • JPEG uses a standard quantization table

More Related