DCT and Transform Coding

DCT and Transform Coding

DCT and Transform Coding Yao Wang Polytechnic University, Brooklyn, NY11201 http://eeweb.poly.edu Outline • Transform coding – General principle •DCT – Definition, basis images – Energy distribution – Approximation with different number of basis images – Quantization of DCT coefficients ©Yao Wang, 2006 EE3414: DCT and Transform Coding 2 A Typical Compression System Input Transformed Quantized Binary Samples parameters parameters bitstreams Transfor- Quanti- Binary mation zation Encoding Prediction Scalar Q Fixed length Transforms Vector Q Variable length Model fitting (Huffman, …... arithmetic, LZW) ©Yao Wang, 2006 EE3414: DCT and Transform Coding 3 Motivation for “Transformation” • Motivation for transformation: – To yield a more efficient representation of the original samples. – The transformed parameters should require fewer bits to code. • Types of transformation used: – For speech coding: prediction • Code predictor and prediction error samples – For audio coding: subband decomposition • Code subband samples – For image coding: DCT and wavelet transforms • Code DCT/wavelet coefficients ©Yao Wang, 2006 EE3414: DCT and Transform Coding 4 Transform Coding • Represent an image as the linear combination of some basis images and specify the linear coefficients. + t 1 t2 t3 t4 ©Yao Wang, 2006 EE3414: DCT and Transform Coding 5 A Typical Transform Coder Transform Coefficient Coded Quantized Coefficients Indices Bitstream Coefficients Input Output Samples Samples Coder Inverse Inverse Forward Decoder Quantizer Transform Quantizer Channel Transform Run-Length Run-Length ©Yao Wang, 2006 EE3414: DCT and Transform Coding 6 Transform Basis Design • Optimality Criteria: – Energy compaction: a few basis images are sufficient to represent a typical image. – Decorrelation: coefficients for separate basis images are uncorrelated. • Karhunen Loeve Transform (KLT) is the Optimal transform for a given covariance matrix of the underlying signal. • Discrete Cosine Transform (DCT) is close to KLT for images that can be modeled by a first order Markov process (i.e., a pixel only depends on its previous pixel). ©Yao Wang, 2006 EE3414: DCT and Transform Coding 7 1D Unitary Transform Consider the N − point signal s(n) as an N - dimensional vector s 0 s = 1 s sN −1 The inverse transform says that s can be represented as the sum of N basis vectors = + + + s t0u0 t1u1 ... tN −1u N −1 where uk corresponds to the k - th transform kernel: u k,0 uk,1 u = k ... uk,N −1 The forward transform says that the expansion coefficient tk can be determined by the inner product of s with uk : N −1 = ()= * tk uk ,s ∑uk;nsn n=0 ©Yao Wang, 2006 EE3414: DCT and Transform Coding 8 1D Discrete Cosine Transform • Can be considered “real” version of DFT – Basis vectors contain only co-sinusoidal patterns DFT DCT π π π π = 1 2 k = 1 2 k + 2 k = α k + u exp j n cos n j sin n uk,n (k)cos (2n 1) k,n N N N N N 2N 1 2 α(0) = ,α(k) = ,k = 1,2,..., N −1 N N 2πk 2πk πk cos 0 sin 0 cos 1 N N 2N π π π 2 k 2 k k = 1 cos 1 + 1 sin 1 u = α(k) cos 3 uk j k 2N N N N N ... ... ... 2πk 2πk πk cos (N −1) sin (N −1) cos (2N +1) N N 2N ©Yao Wang, 2006 EE3414: DCT and Transform Coding 9 Example: 4-point DCT kπ 1 1 2 1 Using u = α(k) cos (2n +1),α(0) = = ,α(k) = = ,k ≠ 0, k ,n 2*4 4 2 4 2 π π 3π cos cos cos 8 4 8 1 3π 0.9239 3π 1 9π 0.3827 cos cos cos 1 1 1 8 1 0.3827 1 4 1 −1 1 8 1 − 0.9239 1D DCT basis are : u = ;u = = ;u = = ;u = = 0 2 1 1 2 5π 2 -0.3827 2 2 5π 2 −1 3 2 15π 2 0.9239 cos cos cos 1 8 - 0.9239 4 1 8 − 0.3827 7π 7π 21π cos cos cos 8 4 8 2 4 For s = , determine the transform coefficients t Also determine the reconstructed vector from all coefficients and two largest coeffcieints. 5 k. 3 Go through on the board ©Yao Wang, 2006 EE3414: DCT and Transform Coding 10 2D Separable Transform Consider the M × N − point image S as a M × N -dimensional array (matrix) S S ... S − 0,0 0,1 0,N 1 S1,0 S1,1 ... S1,N −1 S = ... ... ... ... SM −1,0 SM −1,1 ... SM −1,N −1 The inverse transform says that s can be represented as the sum of M × N basis images = + + + S T0,0U0,0 T0,1U0,1 ... TM −1,N −1U M −1,N −1 where Uk,l corresponds to the (k,l) - th transform kernel: * * * uk,0 uk,0ul,0 uk,0ul,1 ... uk,0ul,N −1 * * * T uk,1 * * * uk,1ul,0 uk,1ul,1 ... uk,1ul,N −1 U = u ()u = []u u ... u − = k,l k l ... l,0 l,1 l,N 1 ... ... ... ... * * * uk,N −1 uk,N −1ul,0 uk,N −1ul,1 ... uk,N −1ul,N −1 The forward transform says that the expansion coefficient Sk can be determined by the inner product of S and Uk,l : M −1 N −1 = ()= * Tk,l Uk,l ,S ∑∑U k,l;m,n Sm,n m=0 n=0 ©Yao Wang, 2006 EE3414: DCT and Transform Coding 11 2D Discrete Cosine Transform • Basis image = outer product of 1D DCT basis vector πk cos 1 2N π k 1 2 = α cos 3 α = α = = − uk;N (k) 2N , (0) , (k) ,k 1,2,..., N 1 N N ... πk cos (2N +1) 2N = ()T Uk,l;M ,N uk;M ul;N kπ lπ kπ lπ kπ lπ cos 1cos 1 cos 1cos 3 ... cos 1cos (2N +1) 2M 2N 2M 2N 2M 2N kπ lπ kπ lπ kπ lπ cos 3cos 1 cos 3cos 3 ... cos 3cos (2N +1) = α(k)α(l) 2M 2N 2M 2N 2M 2N ... ... ... kπ lπ kπ lπ kπ lπ cos (2M +1)cos 1 cos (2M +1)cos 3 ... cos (2M +1)cos (2N +1) 2M 2N 2M 2N 2M 2N ©Yao Wang, 2006 EE3414: DCT and Transform Coding 12 Basis Images of 8x8 DCT Low-Low High-Low Low-High High-High ©Yao Wang, 2006 EE3414: DCT and Transform Coding 13 Example: 4x4 DCT kπ 1 1 2 1 Using u = α(k) cos (2n +1),α(0) = = ,α(k) = = ,k ≠ 0, k ,n 2*4 4 2 4 2 π π 3π cos cos cos 8 4 8 1 3π 0.9239 3π 1 9π 0.3827 cos cos cos 1 1 1 8 1 0.3827 1 4 1 −1 1 8 1 − 0.9239 1D DCT basis are : u = ;u = = ;u = = ;u = = 0 2 1 1 2 5π 2 -0.3827 2 2 5π 2 −1 3 2 15π 2 0.9239 cos cos cos 1 8 - 0.9239 4 1 8 − 0.3827 7π 7π 21π cos cos cos 8 4 8 = ()T using Uk,l uk ul yields: 1 1 1 1 1 −1 −1 1 1 1 1 1 1 −1 −1 1 1 1 1 1 1 1 1 −1 −1 1 1 −1 −1 −1 −1 1 −1 1 1 −1 U = , U = , U = ,U = , ...... 0,0 4 1 1 1 1 0,2 4 1 −1 −1 1 2,0 4 −1 −1 −1 −1 2,2 4 −1 1 1 −1 1 1 1 1 1 −1 −1 1 1 1 1 1 1 −1 −1 1 ©Yao Wang, 2006 EE3414: DCT and Transform Coding 14 1 2 2 0 0 1 3 1 For S = , compute T 0 1 2 1 k,l 1 2 2 −1 = Using Tk,l (Uk ,l ,S) yields, e.g, 1 1 1 1 1 2 2 0 1 1 1 1 1 0 1 3 1 1 18 T = (U ,S) = , = ()1+ 2 + 2 + 0 + 0 +1+ 3 +1+ 0 +1+ 2 +1+1+ 2 + 2 −1 = = 4.5 0,0 0,0 4 1 1 1 1 0 1 2 1 4 4 1 1 1 1 1 2 2 −1 1 −1 −1 1 1 2 2 0 1 −1 1 1 −1 0 1 3 1 1 2 T = (U ,S) = , = ()1− 2 − 2 +1+ 3−1+1+ 2 −1+1− 2 − 2 −1 = − = −0.5 2,2 3,2 4 −1 1 1 −1 0 1 2 1 4 4 1 −1 −1 1 1 2 2 −1 Completing calculation using Matlab yields (using "dct2(S)") : 4.5 − 0.0793 − 3 1.1152 0.4619 − 0.5 0.1913 0 T = 0 2.0391 − 0.5 − 0.3034 − 0.1913 0 0.4619 − 0.5 Reconstruction from top 2x2 coefficients only yields: 1.09 1.54 1.38 0.86 1.44 1.9 1.63 0.95 S = 1.11 1.38 1.63 0.95 0.61 0.68 0.31 0.05 The reconstructed image varies slower than the original, because we cut off some high frequency coefficients DCT on a Real Image Block >>imblock = lena256(128:135,128:135) imblock= 182 196 199 201 203 201 199 173 175 180 176 142 148 152 148 120 148 118 123 115 114 107 108 107 >>dctblock =dct2(imblock) 115 110 110 112 105 109 101 100 dctblock=1.0e+003* 104 106 106 102 104 95 98 105 1.0550 0.0517 0.0012 -0.0246 -0.0120 -0.0258 0.0120 0.0232 99 115 131 104 118 86 87 133 0.1136 0.0070 -0.0139 0.0432 -0.0061 0.0356 -0.0134 –0.0130 112 154 154 107 140 97 88 151 0.1956 0.0101 -0.0087 -0.0029 -0.0290 -0.0079 0.0009 0.0096 145 158 178 123 132 140 138 133 0.0359 -0.0243 -0.0156 -0.0208 0.0116 -0.0191 -0.0085 0.0005 0.0407 -0.0206 -0.0137 0.0171 -0.0143 0.0224 -0.0049 -0.0114 0.0072 -0.0136 -0.0076 -0.0119 0.0183 -0.0163 -0.0014 –0.0035 -0.0015 -0.0133 -0.0009 0.0013 0.0104 0.0161 0.0044 0.0011 -0.0068 -0.0028 0.0041 0.0011 0.0106 -0.0027 -0.0032 0.0016 Low frequency coefficients (top left corner) are much larger than the rest! ©Yao Wang, 2006 EE3414: DCT and Transform Coding 16 Reconstructed Block Original block 182 196 199 201 203 201 199 173 175 180 176 142 148 152 148 120 148 118 123 115 114 107 108 107 115 110 110 112 105 109 101 100 104 106 106 102 104 95 98 105 99 115 131 104 118 86 87 133 112 154 154 107 140 97 88 151 145 158 178 123 132 140 138 133 Reconstructed using top 4x4 coefficients Reconstructed using top 2x2 coefficients only 190 192 195 197 196 189 179 172 162 161 158 154 149 146 143 141 175 169 163 163 164 160 150 141 159 157 154 151 147 143 140 138 147 136 124 120 122 121 114 106 153 151 149 145 141 137 135 133 115 110 103 98 96 94 93 92 145 144 141 138 134 131 128 126 96 104 109 104 93 89 96 104 137 135 133 130 126 123 121 119 102 117 130 123 106 98 109 124 129 128 125 122 119 116 114 113 126 139 148 138 119 111 121 136 123 122 119 117 114 111 109 108 148 155 156 144 125 118 126 138 119 118 116 114 111 108 106 105 ©Yao Wang, 2006 EE3414: DCT and Transform Coding 17 original 1 2 3 4 5 6 7 8 2 4 6 8 From 4x4 coef.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    34 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us