Lossy

1,450 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,450
On SlideShare
0
From Embeds
0
Number of Embeds
37
Actions
Shares
0
Downloads
109
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Lossy

  1. 1. Lossy Compression CIS 658 Fall 2005
  2. 2. Lossy Compression <ul><li>In order to achieve higher rates of compression, we give up complete reconstruction and consider lossy compression techniques </li></ul><ul><li>So we need a way to measure how good the compression technique is </li></ul><ul><ul><li>How close to the original data the reconstructed data is </li></ul></ul>
  3. 3. Distortion Measures <ul><li>A distortion measure is a mathematical quality that specifies how close an approximation is to its original </li></ul><ul><ul><li>Difficult to find a measure which corresponds to our perceptual distortion </li></ul></ul><ul><ul><li>The average pixel difference is given by the Mean Square Error (MSE) </li></ul></ul>
  4. 4. Distortion Measures <ul><li>The size of the error relative to the signal is given by the signal-to-noise ratio (SNR) </li></ul><ul><li>Another common measure is the peak-signal-to-noise ratio (PSNR) </li></ul>
  5. 5. Distortion Measures <ul><li>Each of these last two measures is defined in decibel (dB) units </li></ul><ul><ul><li>1 dB is a tenth of a bel </li></ul></ul><ul><ul><li>If a signal has 10 times the power of the error, the SNR is 20 dB </li></ul></ul><ul><ul><li>The term “decibels” as applied to sounds in our environment usually is in comparison to a just-audible sound with frequency 1kHz </li></ul></ul>
  6. 6. Rate-Distortion Theory <ul><ul><li>We trade off rate (number of bits per symbol) versus distortion this is represented by a rate-distortion function R(D) </li></ul></ul>
  7. 7. Quantization <ul><li>Quantization is the heart of any scheme </li></ul><ul><ul><li>The sources we are compressing contains a large number of distinct output values (infinite for analog) </li></ul></ul><ul><ul><li>We compress the source output by reducing the distinct values to a smaller set via quantization </li></ul></ul><ul><ul><li>Each quantizer can be uniquely described by its partition of the input range (encoder side) and set of output values (decoder side) </li></ul></ul>
  8. 8. Uniform Scalar Quantization <ul><li>The inputs and output can be either scalar or vector </li></ul><ul><li>The quantizer can partition the domain of input values into either equally spaced or unequally spaced partitions </li></ul><ul><li>We now examine uniform scalar quantization </li></ul>
  9. 9. Uniform Scalar Quantization <ul><li>The endpoints of partitions of equally spaced intervals in the input values of a uniform scalar quantizer are called decision boundaries </li></ul><ul><ul><li>The output value for each interval is the midpoint of the interval </li></ul></ul><ul><ul><li>The length of each interval is called the step size  </li></ul></ul><ul><ul><li>A UQT can be midrise or midtread </li></ul></ul>
  10. 10. Uniform Scalar Quantization
  11. 11. Uniform Scalar Quantization <ul><li>Midtread quantizer </li></ul><ul><ul><li>Has zero as one of its output values </li></ul></ul><ul><ul><li>Has an odd number of output values </li></ul></ul><ul><li>Midrise quantizer </li></ul><ul><ul><li>Has a partition interval that brackets zero </li></ul></ul><ul><ul><li>Has an even number of output values </li></ul></ul><ul><li>For  = 1 </li></ul>
  12. 12. Uniform Scalar Quantization <ul><li>We want to minimize the distortion for a given input source with a desired number of output values </li></ul><ul><ul><li>Do this by adjusting the step size  to match the input statistics </li></ul></ul><ul><ul><li>Let B = { b 0 , b 1 , …, b M } be the set of decision boundaries </li></ul></ul><ul><ul><li>Let Y = { y 1 , y 2 , …, y M } be the set of reconstruction or output values </li></ul></ul>
  13. 13. Uniform Scalar Quantization <ul><li>Assume the input is uniformly distributed in the interval [- X max , X max ] </li></ul><ul><ul><li>Then the rate of the quantizer is </li></ul></ul><ul><ul><ul><li>R =  log 2 M  </li></ul></ul></ul><ul><ul><li>R is the number of bits needed to code the M output values </li></ul></ul><ul><ul><li>The step size  is given by </li></ul></ul><ul><ul><ul><li> = 2 X max /M </li></ul></ul></ul>
  14. 14. Quantization Error <ul><li>For bounded input, the quantization error is referred to as granular distortion </li></ul><ul><ul><li>That distortion caused by replacing a whole range of values from a maximum values to ∞ (and also on the negative side) is called the overload distortion </li></ul></ul>
  15. 15. Quantization Error
  16. 16. Quantization Error <ul><li>The decision boundaries b i for a midrise quantizer are </li></ul><ul><ul><li>[( i - 1)  , i  ], i = 1 .. M /2 (for positive data X ) </li></ul></ul><ul><li>Output values y i are the midpoints </li></ul><ul><ul><li>i  -  /2, i = 1.. M /2 (for positive data) </li></ul></ul><ul><li>The total distortion (after normalizing) is twice the sum over the positive data </li></ul>
  17. 17. Quantization Error <ul><li>Since the reconstruction values y i are the midpoints of each interval, the quantization error must lie within the range [-  /2,  /2] </li></ul><ul><ul><li>As shown on a previous slide, the quantization error is uniformly distributed </li></ul></ul><ul><ul><li>Therefore the average squared error is the same as the variance (  d ) 2 of from just the interval [0,  ] with errors in the range shown above </li></ul></ul>
  18. 18. Quantization Error <ul><li>The error value at x is e ( x ) = x -  /2, so the variance is given by </li></ul><ul><li>(  d ) 2 = (1/  )  0  ( e ( x ) - e ) 2 dx </li></ul><ul><li> (  d ) 2 = (1/  )  0  [ x - (  /2 ) - 0] 2 dx </li></ul><ul><li> (  d ) 2 =  2 /12 </li></ul>
  19. 19. Quantization Error <ul><li>In the same way, we can derive the signal variance (  x ) 2 as (2 X max ) 2 /12, so if the quantizer is n bits, M = 2 n then </li></ul><ul><li>SQNR = 10log 10 [(  x ) 2 /(  d ) 2 ] </li></ul><ul><li>SQNR = 10log 10 {[(2 X max ) 2 /12]  [12/  2 ]} </li></ul><ul><li>SQNR = 10log 10 {[(2 X max ) 2 /12]  [12/ (2 X max ) 2 ]} </li></ul><ul><li>SQNR = 10log 10 M 2 = 20 n log 10 2 </li></ul><ul><li>SQNR = 6.02 n dB </li></ul>
  20. 20. Nonuniform Scalar Quantization <ul><li>A uniform quantizer may be inefficient for an input source which is not uniformly distributed </li></ul><ul><ul><li>Use more decision levels where input is densely distributed </li></ul></ul><ul><ul><ul><li>This lowers granular distortion </li></ul></ul></ul><ul><ul><li>Use fewer where sparsely distributed </li></ul></ul><ul><ul><ul><li>Total number of decision levels remains the same </li></ul></ul></ul><ul><ul><li>This is nonuniform quantization </li></ul></ul>
  21. 21. Nonuniform Scalar Quantization <ul><li>Lloyd-Max quantization </li></ul><ul><ul><li>iteratively estimates optimal boundaries based on current estimates of reconstruction levels then updates the level and continues until levels converge </li></ul></ul><ul><li>In companded quantization </li></ul><ul><ul><li>Input mapped using a compressor function G then quantized using a uniform quantizer </li></ul></ul><ul><ul><li>After transmission, quantized values mapped back using an expander function G -1 </li></ul></ul>
  22. 22. Companded Quantization <ul><li>The most commonly used companders are u-law and A-law from telephony </li></ul><ul><ul><li>More bits assigned where most sound occurs </li></ul></ul>
  23. 23. Transform Coding <ul><li>Reason for transform coding </li></ul><ul><ul><li>Coding vectors is more efficient than coding scalars so we need to group blocks of consecutive samples from the source into vectors </li></ul></ul><ul><ul><li>If Y is the result of a linear transformation T of an input vector X such that the elements of Y are much less correlated than X , then Y can be coded more efficiently than X . </li></ul></ul>
  24. 24. Transform Coding <ul><li>With vectors of higher dimensions, if most of the information in the vectors is carried in the first few components we can roughly quantize the remaining elements </li></ul><ul><li>The more decorrelated the elements are, the more we can compress the less important elements without affecting the important ones. </li></ul>
  25. 25. Discrete Cosine Transform <ul><li>The Discrete Cosine Transform (DCT) is a widely used transform coding technique </li></ul><ul><ul><li>Spatial frequency indicates how many times pixel values change across an image block </li></ul></ul><ul><ul><li>The DCT formalizes this notion in terms of how much the image contents change in correspondence to the number of cycles of a cosine wave per block </li></ul></ul>
  26. 26. Discrete Cosine Transform <ul><li>The DCT decomposes the original signal into its DC and AC components </li></ul><ul><ul><li>Following the techniques of Fourier Analysis, any signal can be described as a sum of multiple signals that are sine or cosine waveforms at various amplitudes and frequencies </li></ul></ul><ul><li>The inverse DCT (IDCT) reconstructs the original signal </li></ul>
  27. 27. Definition of DCT <ul><li>Given an input function f ( i , j ) over two input variables, the 2D DCT transforms it into a new function F ( u , v ), with u and v having the same range as i and j . The general definition is </li></ul><ul><li>Where i , u = 0, 1, … M -1, j , v = 0, 1, … N -1; and the constants C ( u ) and C ( v ) are defined by: </li></ul>
  28. 28. Definition of DCT <ul><li>In JPEG, M = N = 8, so we have </li></ul><ul><li>The 2D IDCT is quite similar </li></ul><ul><li>with i, j , u , v = 0, 1, …,7 </li></ul>
  29. 29. Definition of DCT <ul><li>These DCTs work on 2D signals like images. </li></ul><ul><li>For one dimensional signals we have </li></ul>
  30. 30. Basis Functions <ul><li>The DCT and IDCT use the same set of cosine functions - the basis functions </li></ul>
  31. 31. Basis Functions
  32. 32. DCT Examples
  33. 33. DCT Examples <ul><li>The first example on the previous slide has a constant value of 100 </li></ul><ul><ul><li>Remember - C (0) = sqrt(2)/2 </li></ul></ul><ul><ul><li>Remember - cos(0) = 1 </li></ul></ul><ul><ul><li>F 1 (0) = [sqrt(2)/(2  2)]  (1  100 +1  100 + </li></ul></ul><ul><ul><li>1  100 + 1  100 + 1  100 +1  100 + 1  100) </li></ul></ul><ul><ul><li> 283 </li></ul></ul>
  34. 34. DCT Examples <ul><li>For u = 1, notice that cos(  /16) = -cos(15  /16), cos(3  /16)= -cos(13  /16), etc. Also, C (1). So we have: </li></ul><ul><li>F 1 (1) = (1/2)  [cos(  /16)  100 + cos(3  /16)  100 + cos(5  /16)  100 + cos(7  /16)  100 + cos(9  /16)  100 + cos(11  /16)  100 + cos(13  /16)  100 + cos(15  /16)  100] = 0 </li></ul><ul><li>The same holds for F 1 (2), F 1 (3), …, F 1 (7) each = 0 </li></ul>
  35. 35. DCT Examples <ul><li>The second example shows a discrete cosine signal f 2 ( i ) with the same frequency and phase as the second cosine basis function and amplitude 100 </li></ul><ul><ul><li>When u = 0, all the cosine terms in the 1D DCT equal 1. </li></ul></ul><ul><ul><li>Each of the first four terms inside of the parentheses has an opposite (so they cancel). </li></ul></ul><ul><ul><ul><li>E.g. cos  /8 = -cos 7  /8 </li></ul></ul></ul>
  36. 36. DCT Examples <ul><li>F 2 (0) = [sqrt(2)/(2  2)]  1  [100cos(  /8) + 100cos(3  /8) + 100cos(5  /8) + 100cos(7  /8) + 100cos(9  /8) + 100cos(11  /8) + 100cos(13  /8) + 100cos(15  /8)] </li></ul><ul><li>= 0 </li></ul><ul><li>Similarly, F 2 (1), F 2 (3), F 2 (4), …, F 2 (7) = 0 </li></ul><ul><li>For u = 2, because cos(3  /8) = sin(  /8) </li></ul><ul><li>we have cos 2 (  /8) + cos 2 (3  /8) = cos 2 (  /8) + sin 2 (  /8) = 1 </li></ul><ul><li>Similarly, cos 2 (5  /8) + cos 2 (7  /8) = cos 2 (9  /8) + cos 2 (11  /8) = cos 2 (13  /8) + cos 2 (15  /8) = 1 </li></ul>
  37. 37. DCT Examples <ul><li>F 2 (2) =1/2  [cos(  /8)  cos(  /8) + cos(3  /8)  cos(3  /8) + cos(5  /8)  cos(5  /8) + cos(7  /8)  cos(7  /8) + cos(9  /8)  cos(9  /8) + cos(11  /8)  cos(11  /8) + cos(13  /8)  cos(13  /8) + cos(15  /8) + cos(15  /8)]  100 </li></ul><ul><li>= 1/2  (1 + 1 + 1 + 1)  100 </li></ul>
  38. 38. DCT Examples
  39. 39. DCT Characteristics <ul><li>The DCT produces the frequency spectrum F ( u ) corresponding to the spatial signal f ( i ) </li></ul><ul><ul><li>The 0th DCT coefficient F ( 0 ) is the DC coefficient of f ( i ) and the other 7 DCT coefficients represent the various changing (AC) components of f ( i ) </li></ul></ul><ul><ul><ul><li>0th component represents the average value of f ( i ) </li></ul></ul></ul>
  40. 40. DCT Characteristics <ul><li>The DCT is a linear transform </li></ul><ul><ul><li>A transform is linear iff </li></ul></ul><ul><ul><li>Where  and  are constants and p and q are any functions, variables or constants. </li></ul></ul>
  41. 41. Cosine Basis Functions <ul><li>For better decomposition, the basis functions should be orthognal , so as to have the least amount of redundancy </li></ul><ul><li>Functions B p ( i ) and B q ( i ) are orthognal if </li></ul><ul><ul><li>Where “.” is the dot product </li></ul></ul>
  42. 42. Cosine Basis Functions <ul><li>Further, the functions B p ( i ) and B q ( i ) are orthonormal if they are orthognal and </li></ul><ul><ul><li>Orthonormal property guarantees reconstructability </li></ul></ul><ul><ul><li>It can be shown that </li></ul></ul>
  43. 43. Graphical Illustration of 2D DCT Basis Functions
  44. 44. 2D Separable Basis <ul><li>With block size 8, the 2D DCT can be separated into a sequence of 2 1D DCT steps (Fast DCT) </li></ul><ul><ul><li>This algorithm is much more efficient (linear vs. quadratic) </li></ul></ul>
  45. 45. Discrete Fourier Transform <ul><li>The DCT is comparable to the more widely known (in mathematical circles) Discrete Fourier Transform </li></ul>
  46. 46. Other Transforms <ul><li>The Karhunen-Loeve Transform (KLT) is a reversible linear transform that optimally decorrelates the input </li></ul><ul><li>The wavelet transform uses a set of basis functions called wavelets which can be implemented in a computationally efficient manner by means of multi-resolution analysis </li></ul>

×