Top Banner
1 Discrete Cosine Transform (DCT)
33

Discrete Cosine Transform - NTU

Feb 03, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Discrete Cosine Transform - NTU

1

Discrete Cosine Transform (DCT)

Page 2: Discrete Cosine Transform - NTU

2

DCT is a Fourier-related transform similar to DFT, but using only real numbers. It is equivalent to a DFT roughly twice the transform length, operating on real data with “Even symmetry” (since Fourier transform of a real and even function is real and even). The most common variant of DCT is the type-II DCT and its inverse is the type-III DCT.

Page 3: Discrete Cosine Transform - NTU

3

Two related transform are the discrete sine transform (DST), which is equivalent to a DFT of “Real and odd” functions, and the modified DCT (MDCT), which is based on a DCT of overlapping data.The other interesting transform is the discrete Hartley transform (DHT) in which

Even part of DHT = Real part of DFTOdd part of DHT = Imaginary part of DFT

Page 4: Discrete Cosine Transform - NTU

4

DCT is often used in signal and image processing, especially for lossy data compression, because it has a strong “Energy Compaction” property: most of the signal information tends to be concentrated in a few low-frequency components of the DCT, approaching the KLT for signals based on certain limits of Markov processes.DCT is used in JPEG image compression, MJPEG and MPEG video compression.MDCT is used in MP3, AAC, etc. audio compression.

Page 5: Discrete Cosine Transform - NTU

5

Formulation: DCT is a linear and invertible function F: Rn →Rn (where R denotes the set of real numbers.), or equivalently on nxn matrix.

DCT-I:

∑−

=− −

+−+=2

110 ]

1cos[))1((

21 n

kkn

jj jk

nxxxf π

Page 6: Discrete Cosine Transform - NTU

6

A DCT-I of n=5 real numbers abcde is exactly equivalent to a DFT of 8 real numbers abcdedcb (even symmetry), here divided by 2. (In contrast, DCT-II ~ IV involve a half-sample shift in the equivalent DFT.)Note that DCT-I is not defined for n less than 2. (All other DCT types are defined for any positive n.)

Page 7: Discrete Cosine Transform - NTU

7

DCT-II:

Some authors further multiply the fo term by (see below for the corresponding

change in DCT-III) . This makes the DCT-II matrix orthogonal (up to a scale factor), but breaks the direct correspondence with a real-even DFT of half-shifted input.

∑−

=

+=1

0)]

21(cos[

n

kkj kj

nxf π

2/1

Page 8: Discrete Cosine Transform - NTU

8

DCT-III:

Some authors further multiply the x0 term by , this makes the DCT-III matrix orthogonal (up to a scale factor), but breaks the direct correspondence with a real even DFT of half-shifted output.

∑−

=

++=1

10 ])

21(cos[

21 n

kkj kj

nxxf π

2/1

Page 9: Discrete Cosine Transform - NTU

9

DCT-IV:

DCT-IV matrix is orthogonal (up to a scale factor). MDCT is based on DCT-IV with overlapped data.

∑−

=

++=1

0)]

21)(

21(cos[

n

kkj kj

nxf π

Page 10: Discrete Cosine Transform - NTU

10

DCT V-VIII:DCT types I-IV are equivalent to real-even DFTs of even order; therefore, there are 4 additional types of DCT corresponding to real-even DFTs of logically odd order, which have factors of (n + 1/2) in the denominators of the cosine arguments. These variants seem to be rarely used in practice.

Page 11: Discrete Cosine Transform - NTU

11

Inverse Transforms:IDCT-I is DCT-I multiplied by 2/(n-1).IDCT-IV is DCT-IV multiplied by 2/n.IDCT-II is DCT-III multiplied by 2/n (and versa).

Page 12: Discrete Cosine Transform - NTU

12

ComputationDirect application of the above formulas would require O(n2) operations, as in the FFT it is possible to compute the same thing with only O(nlogn) complexity by factorizing the computation. (One can also compute DCTs via FFTs combined with O(n)) pre- and post-processing steps.)

Page 13: Discrete Cosine Transform - NTU

13

References:1. Rao and Yip, Discrete Cosine Transform: Algorithms, Advantages, Applications; Academic Press, Boston, 1990.2. Arai, Agui, Nakajima, A Fast DCT-SQ scheme for Images, Trans. On IEICE-E, 71(11), 1095, Nov. 1998.3. Tseng and Millen, On Computing the DCT, IEEE Trans. On Computers, pp. 966-968, Oct. 1978.4. Frigo and Johnson, The Design and Implementation of FFTW3, IEEE Proceedings, vol. 93, no. 2, pp. 216-231, 2005.

Page 14: Discrete Cosine Transform - NTU

14

The implementation of the 2D-IDCTLet the 8-point 1-D DCT of input data f(x) be:

First the 1-D DCT is applied to all the rows of the 2-D input f(y,x):

∑=

+=

7

08 16

)12(cos)(2

)(x

u uxxfCuS π

∑=

+=

7

08 16

)12(cos),(2

),(x

ur

uxxyfCuyS π

(1)

(2)

Page 15: Discrete Cosine Transform - NTU

15

Then the 1-D DCT is applied to the columns of the results of (2):

By substitution we get the formulation of the 2-D DCT:

∑=

+=

7

08 16

)12(cos),(2

),(y

ru vyuySCuvS π

∑∑= =

++=

7

0

7

0 16)12(cos

16)12(cos),(

22),(

y x

uv vyuxxyfCCuvS ππ

(3)

(4)

Page 16: Discrete Cosine Transform - NTU

16

Fast 1-D DCT AlgorithmsDefine Eqn. (1) can be written as:

Since

. and,16

,16

2 βαπβπα +=== Huux

∑∑==

+=+

=7

0

7

08 )cos()(

216)12(cos)(

2)(

x

u

x

u xfCuxxfCuS βαπ

16)15(2cos

162coscos)cos(2coscos2

)(

uxuxHHW

ππββαβ −+=+=

Page 17: Discrete Cosine Transform - NTU

17

If we constitute a sequence of elements f(k), k = 0, 1, …, 15 with

∑=

−+=

7

08 ]

16)15(2cos

162)[cos()(

16cos4

xu

uxuxxfuSuC

πππ

⎩⎨⎧

≥∀−<∀

=8),15(8 ),(

)(kkfkkf

kf

(5)

Page 18: Discrete Cosine Transform - NTU

18

We can re-write (5) as

WhenDecaese the 16-point DFT is defined by

∑ ∑= =

−==

15

0

15

0

162

8 })(Re{16

2cos)()(16

cos4k k

ukj

u

ekfukkfuSuC

πππ

1−=j

∑=

−=

15

0

162

16 )()(k

ukjekfuF

π

Page 19: Discrete Cosine Transform - NTU

19

We have the following DCT v.s. DFT relationship

Instead of performing an IDCT an IDFT of twice the length is performed. IDFT can be implemented by IFFT with complexity O(NlogN)!

)}(Re{)(16

cos4168 uFuSu

Cu

=π : only the first 8 values

are needed.

Page 20: Discrete Cosine Transform - NTU

20

The multiplication by seems not so efficient. However, bear in mind that the last operation before the IDCT is the “Quantization”. That means every value is to be multiplied with a certain constant (1/Quantization factor) depending on its position in DCT matrix. So we can merge the multiplications by and the multiplication by Quantizer dependent constant together. As a result, the Quantization and DCT-DFT transform is performed in one step.

16cos4 u

Cu

π

16cos4 u

Cu

π

Page 21: Discrete Cosine Transform - NTU

21

Let XM = (f(0), f(1), f(2), f(3), f(4), f(5), f(6), f(7)): original dataFM = ( F(0), F(1), F(2), F(3), F(4),

F(5), F(6), F(7)): scaled transformed data

Define P(a,b) =We can establish a matrix TM:

161

81 8

181

81

81

81

81

162cos

162cos ba ππ

+

Page 22: Discrete Cosine Transform - NTU

22

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

=

)56,49()63,42()70,35()77,28()84,21()91,14()98,7()105,0()48,42()54,36()60,30()66,24()72,18()78,12()84,6()90,0()40,35()45,30()50,25()55,20()60,15()65,10()70,5()75,0()32,28()36,24()40,20()44,16()48,12()52,8()56,4()60,0()24,21()27,18()30,15()33,12()36,9()39,6()42,3()045()16,14()18,12()20,10()22,8()24,6()26,4()28,2()30,0(

)8,7()9,6()10,5()11,4()12,3()13,2()14,1()15,0(2

)0,0(2

)0,0(2

)0,0(2

)0,0(2

)0,0(2

)0,0(2

)0,0(2

)0,0(

PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP

PPPPPPPP

TM

Page 23: Discrete Cosine Transform - NTU

23

FM = XM x (1/8)TM

Because

Define

;cos)2cos()cos()cos(cos );cos(cos

ααπαπαπααα

=++=−=−=−=

n

8sin

83cos;

22

4cos

82cos;

8cos 642

πππππ====== kkk

Page 24: Discrete Cosine Transform - NTU

24

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

−+−−−−+−−+−−+−−−−−++−+−−−−

−−−−−−−+−−−−++−−−−−−+−−−−−−−+++

=

111111

1111111111

11111111

11111111

224466664422

44444444

664422224466

664422224466

44444444

224466664422

kkkkkkkkkkkkkkkkkkkk

kkkkkkkkkkkk

kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk

TM

Page 25: Discrete Cosine Transform - NTU

25

XM = FM x (8TM-1) = FM x L; (L = 8TM

-1)

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

−+−−−+++−−−−++−−−−+−−+−−

−+−+−+−−−−+−+−−−−−−

−−++−−−+−++−−−−+−+−−−+−+−

−−+−−−+−−+−+−−

=

111111111111111111111111

1111111111111111

1111111111111111

11111111

224246246422

4444

664642642466

664642642466

4444

224246246422

CCCCCCCCCCCCCCCC

CCCCCCCCCCCC

CCCCCCCCCCCCCCCC

CCCCCCCCCCCC

L

Page 26: Discrete Cosine Transform - NTU

26

Where

The matrix L can be factored as:L = B1 x M x A1 x A2 x A3

with:

8sin2

83cos2

28

2cos2;8

cos2

6

42

ππ

ππ

==

===

C

CC

Page 27: Discrete Cosine Transform - NTU

27

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

−−

−−=

1110000000001100101100000000001010110000000011001110000000000001

1B

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

−−=

1000000000000000000000000000000100000000000000001000000001

26

4

62

4

CCC

CC

C

M

Page 28: Discrete Cosine Transform - NTU

28

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

−−

=

10000000

0010000100100001000000010100000010000100000001000001101000011010

1A

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

=

0000000101010000100000000000010001010000001010000010100010000010

2A

Page 29: Discrete Cosine Transform - NTU

29

So the IDFT can be performed by 5 steps:

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

−−

=

0001100000011000001001001000000101000010010000100010010010000001

3A

Page 30: Discrete Cosine Transform - NTU

30⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪

⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪

+=

−=

−=

+=

+=

−=

+=

−=

=

=

21

)7(81)1(

81

21

)5(81)3(

812

)7(81)1(

811

)3(81)5(

81

)6(81)2(

81

)6(81)2(

81

)4(81

)0(161

:1

7

6

5

4

3

2

1

0

temptempa

FFa

temptempa

FFtemp

FFtemp

FFa

FFa

FFa

Fa

Fa

B

⎪⎪⎪⎪⎪

⎪⎪⎪⎪⎪

=+−=

=+−=

====

77

26646

455

66244

33

422

11

00

)(

)(:

abCaCab

CabCaCab

abcab

abab

M

Page 31: Discrete Cosine Transform - NTU

31

⎪⎪⎪⎪⎪⎪

⎪⎪⎪⎪⎪⎪

====

+=−=−=

−=−=

77

36

45

4

103

322

101

50

76

3

33

:1

bnbnbntempn

bbnbbnbbn

btempnbbtemp

A

⎪⎪⎪⎪⎪

⎪⎪⎪⎪⎪

−=−=−=+=+=

===

057

636

215

634

213

42

01

70

:2

nnmnnmnnmnnmnnm

nmnmnm

A

⎪⎪⎪⎪⎪

⎪⎪⎪⎪⎪

−=−=+=+=−=−=+=+=

04

23

15

76

76

15

23

04

)7()6()5()4()3()2()1()0(

:3

mmfmmfmmfmmfmmfmmfmmfmmf

A

Page 32: Discrete Cosine Transform - NTU

32

In part M, a simplification can be made:

So define)()(

)()( )(

626646

6666266426642

624646

6464662466244

CCaaaCCaCaCaCaCaCab

CCaaaCCaCaCaCaCaCab

+++−=+−+−=+−=

−−+−=+−−−=+−=

44

)(4 and

66

44

646

6262

tempRabtempQab

aaCtempCCRCCQ

−=−−=

+=+=−=

Page 33: Discrete Cosine Transform - NTU

33

If you count the operations you will get 29 additions and 5 multiplications. Because an 8x8 2-D DCT can be computed by applying 8-point 1-D DCT to each row and each column of the 2D data. Therefore, 2x8x29 = 464 additions and 2x8x5 = 80 multiplications are required in total.A more efficient DCT algorithm has been proposed by Feig and Winograd in IEEE Trans. on ASSP, pp. 2174-2193, 1992.