algorithms of scientific computing
play

Algorithms of Scientific Computing Discrete Cosine Transform (DCT) - PowerPoint PPT Presentation

Technische Universit at M unchen Algorithms of Scientific Computing Discrete Cosine Transform (DCT) Michael Bader Summer Term 2012 Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 1


  1. Technische Universit¨ at M¨ unchen Algorithms of Scientific Computing Discrete Cosine Transform (DCT) Michael Bader Summer Term 2012 Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 1

  2. Technische Universit¨ at M¨ unchen DFT and Symmetry INPUT TRANSFORM real symmetry f n ∈ R → Real DFT (RDFT) even symmetry f n = f − n → Discrete Cosine Transform (DCT) odd symmetry f n = − f − n → Discrete Sine Transform (DST) “QUARTER-WAVE” INPUT TRANSFORM even symmetry f n = f − n − 1 → QW-DCT odd symmetry f n = − f − n − 1 → QW-DST Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 2

  3. Technische Universit¨ at M¨ unchen Application Example: Compression of Image Data (JPEG) Compression steps of the JPEG method 1. Conversion into a suitable colour model (YCbCr, e.g.), separation of brightness and colour information 2. Downsampling (in particular of the colour components) 3. blockwise “quarter-wave discrete cosine transform” (blocks of size 8 × 8) 4. Quantification of the coefficients ( → reduce information) 5. run-length encoding, Huffman/arithmetic coding (loss-free compression of the quantified coefficients) Example: jpeg on matlab central (see link on webpage) Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 3

  4. Technische Universit¨ at M¨ unchen Discrete Fourier Transform (DFT) Definition: For a vector of N complex numbers ( f 0 , . . . , f N − 1 ) , the discrete Fourier transform is given by the vector ( F 0 , . . . , F N − 1 ) , where N − 1 � F k = 1 f n e − i 2 π nk / N . N n = 0 Interpretation: • as trigonometric interpolation/approxmiation • as approximation of the coefficients of the Fourier series Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 4

  5. Technische Universit¨ at M¨ unchen Fourier Coefficients and Numerical Quadrature For a 2 π -periodic function f , the corresponding Fourier series is defined as � 2 π � ∞ c k = 1 f ( x ) e − ikx dx c k e ikx , f ( x ) ∼ mit 2 π k = −∞ 0 The c k are called (continuous) Fourier coefficients . If f is piecewisely smooth, Fourier series converges pointwisely (i.e. for each x ) towards 1 2 ( f ( x + ) + f ( x − )) , i.e. in particular towards f ( x ) , if f is coninuously differentiable at x . Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 5

  6. Technische Universit¨ at M¨ unchen Approximate Computation of c k The continuous Fourier coefficients are given as � 2 π c k = 1 f ( x ) e − ikx dx 2 π 0 Approaches to compute c k approximately: K � c k e ikx • compute c k only for ± k = 0 , . . . , K ; then: f ( x ) ≈ k = − K � 2 π f ( x ) e − ikx dx numerically • compute integral 0 Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 6

  7. Technische Universit¨ at M¨ unchen Computation of c k via Trapezoidal Sum Trapezoidal sum : for equidistant x n := 2 π n N : � � � 2 π N − 1 � g ( x ) dx ≈ T N { g } := 2 π 1 g ( x n ) + 1 2 g ( x 0 ) + 2 g ( x N ) N n = 1 0 Use g ( x ) := f ( x ) e − ikx and f n := f ( x n ) ; hence: � � N − 1 � c k ≈ 1 1 1 f n e − i 2 π nk / N + 1 2 f 0 e 0 + 2 π T N { f ( x ) e − ikx } 2 f N e − i 2 π Nk / N = N n = 1 � � N − 1 � 1 f 0 f n e − i 2 π nk / N + f N = 2 + N 2 n = 1 Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 7

  8. Technische Universit¨ at M¨ unchen Computation of c k via Trapezoidal Sum (2) If f 0 = f N (periodic data), we obtain N − 1 � c k ≈ F k = 1 f n e − i 2 π nk / N N n = 0 ⇒ F k are approximations of c k ⇒ approximate computation leads to solution of the interpolation problem ⇒ approximation error is of order O ( N − 2 ) For f 0 � = f N , or for “discontinuities”, we get a recommendation: Average Values at Endpoints and Discontinuities (AVED) Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 8

  9. Technische Universit¨ at M¨ unchen Computation of c k via Midpoint Rule Midpoint rule: evaluate g ( x ) at midpoints x n : � � � 2 π N − 1 � n + 1 x n := 2 π g ( x ) dx ≈ 2 π 2 g ( x n ) with . N N n = 0 0 With g ( x ) := f ( x ) e − ikx and f n := f ( x n ) , we obtain: N − 1 � F k := 1 f n e − i 2 π ( n + 1 2 ) k / N c k ≈ � N n = 0 “Quarter-Wave Discrete Fourier Transform” Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 9

  10. Technische Universit¨ at M¨ unchen Quarter-Wave Discrete Fourier Transform • new variant of DFT: N − 1 N − 1 � � F k := 1 � f n e − i 2 π ( n + 1 2 ) k / N F k e i 2 π ( n + 1 � 2 ) k / N f n := N n = 0 k = 0 • Comparison with coefficients F k of the “usual” DFT: F k e i π k / N = � F k = � F k ω k / 2 N • Supporting points compared to “usual” DFT shifted by a “quarter wave length” (midpoints of intervals). • Derivation via midpoint rule motivates usage for piecewise constant data ⇒ Transformation of image data Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 10

  11. Technische Universit¨ at M¨ unchen Quarter-Wave DFT on Symmetric Data Given 2 N real-valued input data f 0 , . . . , f 2 N − 1 with symmetry f 2 N − n − 1 = f n Inserting the symmetric data in Quarter-Wave DFT results in 2 N − 1 � 1 − k ( n + 1 2 ) � F k = f n ω 2 N 2 N n = 0 N − 1 � N − 1 � 1 + 1 − k ( n + 1 2 ) − k ( 2 N − n − 1 + 1 2 ) = f n ω f 2 N − n − 1 ω 2 N 2 N 2 N 2 N n = 0 n = 0 � � � � � � N − 1 N − 1 � � n + 1 π k 1 = 1 − k ( n + 1 2 ) − k ( − n − 1 2 ) 2 = + ω f n f n cos ω . 2 N 2 N 2 N N N n = 0 n = 0 Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 11

  12. Technische Universit¨ at M¨ unchen Quarter-Wave DFT on Symmetric Data (2) Quarter-Wave DFT of symmetric data results in real-valued coefficients: � � � � N − 1 � n + 1 π k F k = 1 � 2 for k = 0 , . . . , 2 N − 1 f n cos N N n = 0 Additional symmetry: � � � � N − 1 � n + 1 π ( 2 N − k ) 1 � 2 F 2 N − k = f n cos N N n = 0 � � � � N − 1 � n + 1 1 2 π n + π − π k = − � 2 = f n cos F k N N n = 0 ⇒ again: only N independent coefficients Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 12

  13. Technische Universit¨ at M¨ unchen Quarter-Wave Even Discrete Cosine Transform backward transform: � � � � 2 N − 1 N − 1 � � n + 1 π k F 2 N − k = − � � F k F k e i 2 π ( n + 1 � 2 ) k / 2 N f n = � � 2 f n := − → F 0 + 2 F k cos N k = 0 k = 1 Definition of the quarter-wave even DCT: � � � � � � � � N − 1 N − 1 � n + 1 � n + 1 π k π k F k = 1 � f n = � � 2 2 F 0 + 2 f n cos F k cos N N N n = 0 k = 1 N real-valued data ← → N real-valued coefficients (no symmetry any more in data/coefficients!) Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 13

  14. Technische Universit¨ at M¨ unchen 2D Cosine Transform Definition of the 2D-DCT: � � � � � � � � N − 1 M − 1 � � n + 1 m + 1 π k π l 1 � 2 2 F kl = f nm cos cos N · M N M n = 0 m = 0 � � � � � � � � N − 1 � M − 1 � n + 1 m + 1 π k π l ′ � 2 2 ′ f nm = 4 F kl cos cos N M k = 0 l = 0 N − 1 � N − 1 � ′ x k := x 0 shortened notation: 2 + x k k = 0 k = 1 Application: blockwise 2D-DCT in JPEG/MPEG compression Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 14

  15. Technische Universit¨ at M¨ unchen Reduction of the 2D-FCT to 1D-FCTs In the 2D cosine transform, we can rearrange: � � � � � � � � N − 1 N − 1 � � n + 1 m + 1 π k π l 1 � 2 2 F kl = f nm cos cos N 2 N N n = 0 m = 0 � � �� � � � � � � N − 1 N − 1 � � m + 1 n + 1 1 1 π l π k 2 2 = f nm cos cos . N N N N n = 0 m = 0 � �� � := � F nl • For each n , � F nl are computed via N 1D transforms • we may first 1D-transform all rows and then all columns to get the 2D-transform Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 15

  16. Technische Universit¨ at M¨ unchen Application Example: Compression of Image Data (JPEG) Compression steps of the JPEG method 1. Conversion into a suitable colour model (YCbCr, e.g.), separation of brightness and colour information 2. Downsampling (in particular of the colour components) 3. blockwise “quarter-wave discrete cosine transform” (blocks of size 8 × 8) 4. Quantification of the coefficients ( → reduce information) 5. run-length encoding, Huffman/arithmetic coding (loss-free compression of the quantified coefficients) Example: jpeg on matlab central (see link on webpage) Michael Bader: Algorithms of Scientific Computing Discrete Cosine Transform (DCT), Summer Term 2012 16

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend