Upload
sagara01355
View
45
Download
0
Tags:
Embed Size (px)
Citation preview
Chapter 18Chapter 18
Discrete Cosine TransformDiscrete Cosine Transform
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 18, Slide 2
Learning ObjectivesLearning Objectives
Introduction to the DCT and IDCT.Introduction to the DCT and IDCT. Decomposition of a 2-D DCT to two 1-D Decomposition of a 2-D DCT to two 1-D
DCTs.DCTs. Implementation of a 2-D DCT using a 1-Implementation of a 2-D DCT using a 1-
D DCT.D DCT.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 18, Slide 3
IntroductionIntroduction
To perform the JPEG coding, an image (in colour or grey To perform the JPEG coding, an image (in colour or grey scales) is first subdivided into blocks of 8x8 pixels.scales) is first subdivided into blocks of 8x8 pixels.
The Discrete Cosine Transform (DCT) is then performed on The Discrete Cosine Transform (DCT) is then performed on each block.each block.
This generates 64 coefficients which are then quantised to This generates 64 coefficients which are then quantised to reduce their magnitude.reduce their magnitude.
DCT
IDCT
Quantiser
Dequantiser
EntropyEncoder
EntropyDecoder
Channelor
Storage
reversezigzag
zigzag
An8x8
block
Im age
8 pixels
8 p
ixels
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 18, Slide 4
IntroductionIntroduction
The coefficients are then reordered into a one-dimensional array The coefficients are then reordered into a one-dimensional array in a zigzag manner before further entropy encoding.in a zigzag manner before further entropy encoding.
The compression is achieved in two stages; the first is during The compression is achieved in two stages; the first is during quantisation and the second during the entropy coding process.quantisation and the second during the entropy coding process.
JPEG decoding is the reverse process of coding.JPEG decoding is the reverse process of coding.
DCT
IDCT
Quantiser
Dequantiser
EntropyEncoder
EntropyDecoder
Channelor
Storage
reversezigzag
zigzag
An8x8
block
Im age
8 pixels
8 p
ixels
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 18, Slide 5
Implementation of the DCTImplementation of the DCT
DCT-based codecs use a two-DCT-based codecs use a two-dimensional version of the transform.dimensional version of the transform.
The 2-D DCT and its inverse (IDCT) of The 2-D DCT and its inverse (IDCT) of an N x N block are shown below:an N x N block are shown below:
Note: The DCT is similar to the DFT Note: The DCT is similar to the DFT since it decomposes a signal into a series since it decomposes a signal into a series of harmonic cosine functions.of harmonic cosine functions.
2-D DCT:2-D DCT:
2-D IDCT:2-D IDCT:
1
0
1
0
]2
)12(cos[]
2
)12(cos[),()()(
2),(
N
y
N
x N
vy
N
uxyxfvCuC
NvuF
1
0
1
0
]2
)12(cos[]
2
)12(cos[),()()(
2),(
N
v
N
u N
vy
N
uxvuFvCuC
Nyxf
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 18, Slide 6
2-D DCT using a 1-D DCT Pair2-D DCT using a 1-D DCT Pair
One of the properties of the 2-D DCT is One of the properties of the 2-D DCT is that it is separable meaning that it can that it is separable meaning that it can be separated into a pair of 1-D DCTs.be separated into a pair of 1-D DCTs.
To obtain the 2-D DCT of a block a 1-D To obtain the 2-D DCT of a block a 1-D DCT is first performed on the rows of DCT is first performed on the rows of the block then a 1-D DCT is performed the block then a 1-D DCT is performed on the columns of the resulting block.on the columns of the resulting block.
The same applies to the IDCT.The same applies to the IDCT. This process is illustrated on the This process is illustrated on the
following slide.following slide.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 18, Slide 7
2-D DCT using a 1-D DCT Pair2-D DCT using a 1-D DCT PairRaw B lock of P ixels
F inal result after DCT by colum ns Result after DCT by rows
128
128
125
127
127
130 128 134 130 128 128
128128130134128130
126 130 127 130 131 128 127
127127
131
131
131
129
129
128
130129
132
133131
129
126127
130
134131129
131
124 128
132
129 134134 136 136 137 134 132
132135140137138136135133
365
365
362
359
368
370
378
383
-1
-1
-3
-3
1
0
-3
-1
-4
-4
-4
-3
1
-3
-6
-6
1
1
0
0
-1
-3
0
2
-3
-3
-3
-3
1
1
-1
-1
-2
00-3
1
1
-3
-3
1
-1
-3
2
0
-2
-1
-1
3
3
1
1
-1
-2
2
-3
pixel[n]
An 8x8block
Part of a picture
Colum ns (256 pixels)
Row
s (
256 p
ixels
)
p ixel[256+n]
pixel[n+1]
1024
-18
11
0
-2
-4
0
2
-4
-1
-11
-1
1
-5
2 2
1 1
-3 -3
0 -1
0 1 0
-2
-1
1 0 -1 -1 -2
0 -1 -1 -1
011-1
-3 -1 0 -2
3-2-23-3
0 1
-1
-12
0
0 -4 -6 0 1
0
2 4-22
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 18, Slide 8
2-D DCT using a 1-D DCT Pair2-D DCT using a 1-D DCT Pair
1-D DCT:1-D DCT:
1-D IDCT:1-D IDCT:
]2
)12(cos[)()(
2)(
1
0
N
i N
kiixkC
NkX
]2
)12(cos[)()(
2)(
1
0
N
kN
kikXkC
Nix
k = 0, 1, 2, …, N-1.and i = 0, 1, 2, …, N-1.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 18, Slide 9
Implementation IssuesImplementation Issues Precalculate the DCT coefficients and Precalculate the DCT coefficients and
scale them (see scale them (see \Links\DCT Coeffs.pdf).).
0.707
0.981
0.924
0.707
0.831
0.707 0.707 0.707 0.707 0.707 0.707
-.981-0.8310.556-0.1950.1950.556
0.383 -0.383 -.0924 -0.924 -0.383+0.38
30.924
-0.8310.195
0.556
0.707
0.981
-0.707
-0.195
-0.707
0.9810.556
0.707
-0.8310.831
0.707
-0.556-0.981
-.707
0.981-0.9810.556
0.707
0.831 -0.195
-0.707
0.383 0.924-0.924 0.383 -0.383 0.924 -0.924 0.383
-0.1950.556-0.8310.981-0.9810.8310.5560.195
1448
2008
1892
1448
1702
1448 1448 1448 1448 1448 1448
-2008-1702-1137-3993991137
783 -783 -1892 -1892 -783 783 1892
-1702399
-1137
1448
2008
-1448
-399
-1448
20081137
1448
-17021702
1448
-1137-2008
-1448
399-20081137
1448
1702 -399
-1448
783 1892-1892 -783 -783 1892 -1892 783
-3991137-17022008-20081702-1137399
Multiplied by 211
]16
)12(cos[),(*2
kikicoef
coef(i, k) in Q12 form at
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 18, Slide 10
Block-based DCT and IDCT in CBlock-based DCT and IDCT in C
The most straightforward way of The most straightforward way of implementing a DCT and an IDCT is to implementing a DCT and an IDCT is to use the 1-D DCT and IDCT.use the 1-D DCT and IDCT.
The following C code shows how to The following C code shows how to translate the 1-D equations for the DCT translate the 1-D equations for the DCT and IDCT into C code.and IDCT into C code.
The program also takes into account the The program also takes into account the numerical issues associated with fixed-numerical issues associated with fixed-point processors.point processors.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 18, Slide 11
Implementation IssuesImplementation Issues(1)(1) The program runs on the DSK with the C6711 and does The program runs on the DSK with the C6711 and does
not use any communication with the host.not use any communication with the host.
(2)(2) The The scenary.hscenary.h file is quite large (256x256 8-bit pixels or file is quite large (256x256 8-bit pixels or 65536 bytes) and therefore needs to be located in a specific 65536 bytes) and therefore needs to be located in a specific memory location in the DSK. By using the memory location in the DSK. By using the #pragma #pragma DATA_SECTION (…)DATA_SECTION (…) directive the picture can be located directive the picture can be located in the DRAM (origin address 0x0800 0000).in the DRAM (origin address 0x0800 0000).
(3)(3) For example, For example, #pragma DATA_SECTION (image_in, #pragma DATA_SECTION (image_in, “ext_sdram”)“ext_sdram”) allows the image_in data array to be allows the image_in data array to be loaded into the section called “ext_sdram” which is loaded into the section called “ext_sdram” which is defined in the command file. The same applies to defined in the command file. The same applies to image_out.image_out.
(4) The directory:(4) The directory:
..\ Chapter 18 - Discrete Cosine transform\DCT_C_Fixed..\ Chapter 18 - Discrete Cosine transform\DCT_C_Fixed
contains the entire source and executable files required. contains the entire source and executable files required. The program can be loaded into the DSK and by using The program can be loaded into the DSK and by using the display feature of the CCS as shown below the the display feature of the CCS as shown below the contents of image_in and image_out can be displayed and contents of image_in and image_out can be displayed and compared.compared.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 18, Slide 12
Implementation IssuesImplementation Issues
Graph properties for Graph properties for image_inimage_in
Graph properties for Graph properties for image_outimage_out
image_inimage_in
image_outimage_out
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 18, Slide 13
DCT Code and LinksDCT Code and Links
Code location:Code location: ……\Chapter 18 - Discrete Cosine transform\DCT_C_Fixed\Chapter 18 - Discrete Cosine transform\DCT_C_Fixed
Projects:Projects: Fixed Point in C language: Fixed Point in C language: dct_c_fixed.pjtdct_c_fixed.pjt
Links:Links: \Links\Imaging Kit.pdf