Chapter 18 - Discrete Cosine Transform

Download Report

Transcript Chapter 18 - Discrete Cosine Transform

Chapter 18
Discrete Cosine Transform
Learning Objectives



Chapter 18, Slide 2
Introduction to the DCT and IDCT.
Decomposition of a 2-D DCT to two 1-D
DCTs.
Implementation of a 2-D DCT using a 1D DCT.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002
Introduction
8 pixels
8 pixels
An
8x8
block
Image
DCT
Quantiser
zigzag
Entropy
Encoder
Channel
or
Storage
IDCT



Chapter 18, Slide 3
Dequantiser
reverse
zigzag
Entropy
Decoder
To perform the JPEG coding, an image (in colour or grey
scales) is first subdivided into blocks of 8x8 pixels.
The Discrete Cosine Transform (DCT) is the performed on
each block.
This generates 64 coefficients which are then quantised to
reduce their magnitude.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002
Introduction
8 pixels
8 pixels
An
8x8
block
Image
DCT
Quantiser
zigzag
Entropy
Encoder
Channel
or
Storage
IDCT



Chapter 18, Slide 4
Dequantiser
reverse
zigzag
Entropy
Decoder
The coefficients are then reordered into a one-dimensional array
in a zigzag manner before further entropy encoding.
The compression is achieved in two stages; the first is during
quantisation and the second during the entropy coding process.
JPEG decoding is the reverse process of coding.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002
Implementation of the DCT
DCT-based codecs use a twodimensional version of the transform.
The 2-D DCT and its inverse (IDCT) of
an N x N block are shown below:





Chapter 18, Slide 5
2-D DCT:
N 1 N 1
2
(2 x  1)u
(2 y  1)v
F (u, v)  C (u)C (v) f ( x, y) cos[
] cos[
]
N
2N
2N
y 0 x 0
2-D IDCT:
2 N 1 N 1
(2 x  1)u
(2 y  1)v
f ( x, y)   C (u )C (v) F (u, v) cos[
] cos[
]
N v 0 u 0
2N
2N
Note: The DCT is similar to the DFT
since it decomposes a signal into a series
of harmonic cosine functions.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002
2-D DCT using a 1-D DCT Pair




Chapter 18, Slide 6
One of the properties of the 2-D DCT is
that it is separable meaning that it can
be separated into a pair of 1-D DCTs.
To obtain the 2-D DCT of a block a 1-D
DCT is first performed on the rows of
the block then a 1-D DCT is performed
on the columns of the resulting block.
The same applies to the IDCT.
This process is illustrated on the
following slide.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002
2-D DCT using a 1-D DCT Pair
Columns (256 pixels)
Raw Block of Pixels
128 127 130 128 134 130 128 128
128 127 130 128 134 130 128 128
Rows (256 pixels)
An 8x8
block
125 126 130 127 130 131 128 127
124 128 127 126 129 130 127 127
131 132 130 129 132 128 129 131
pixel[n]
129 131 134 131 133 129 131 131
129 134 134 136 136 137 134 132
pixel
[256+n]
133 135 136 138 137 140 135 132
pixel[n+1]
Part of a picture
Final result after DCT by columns
Result after DCT by rows
1024
-4
-11
0
-4
-6
0
1
365 -1
-4
1
1
-3
1
3
-18
-1
1
0
2
-2
2
4
365 -1
-4
1
1
-3
1
3
11
-1
-5
2
0
0
1
-1
362 -3
-4
0
-3
-1
2
1
0
2
2
-3
3
-2-1 -2
3
359 -3
-3
0
-3
-3
0
-1
0
1
1
1
0
-1
-1
-2
368
1
1
-1
1
-3
-2
1
-4
-3
-3
-1
-3
-1
0
-2
370
0
-3
-3
-1
-1
-1
2
-2
0
-1
-2
-1
1
1
0
378 -3
-6
0
-3
-2
-1
-2
2
0
1
0
0
-1
-1
-1
383 -1
-6
2
-3
0
0
-3
Chapter 18, Slide 7
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002
2-D DCT using a 1-D DCT Pair


1-D DCT:
1-D IDCT:
N 1
2
(2i  1)k
C (k ) x(i) cos[
]
N
2
N
i 0
X (k ) 
x(i) 
2
N
N 1
(2i  1)k
]
2N
C(k ) X (k ) cos[
k 0
k = 0, 1, 2, …, N-1.
and i = 0, 1, 2, …, N-1.
Chapter 18, Slide 8
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002
Implementation Issues

Precalculate the DCT coefficients and
scale them (see \Links\DCT Coeffs.pdf).
2 * coef (i, k )  cos[
(2i  1)k
]
16
0.707 0.707 0.707 0.707 0.707 0.707 0.707 0.707
0.981 0.831 0.556 0.195 -0.195 0.556 -0.831 -.981
0.924 0.383 -0.383 -.0924 -0.924 -0.383
+0.38
0.924
3
0.831 -0.195 -0.981 -0.556 0.556 0.981 0.195 -0.831
0.707 -0.707 -.707 0.707 0.707 -0.707 -0.707 0.707
0.556 -0.981 0.981 0.831 -0.831 -0.195 0.981 0.556
0.383 -0.924 0.924 0.383 -0.383 0.924 -0.924 0.383
0.195 0.556 0.831 -0.981 0.981 -0.831 0.556 -0.195
Multiplied by 211
coef(i, k) in Q12 format
1448
1448
1448
1448
1448
1448
2008
1702
1137
399
-399
-1137 -1702 -2008
1892
783
-783
-1892 -1892
-783
783
1892
1702
-399
-2008 -1137 1137
2008
399
-1702
1448 -1448 -1448 1448
1137 -2008
Chapter 18, Slide 9
399
1448
1448
1448 -1448 -1448 1448
1702 -1702
-399
-783
-783
2008 -1137
783
-1892 1892
1892 -1892
783
399
-1137 1702 -2008 2008 -1702 1137
-399
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002
Block-based DCT and IDCT in C



The most straightforward way of
implementing a DCT and an IDCT is to
use the 1-D DCT and IDCT.
The following C code shows how to
translate the 1-D equations for the DCT
and IDCT into C code.
The program also takes into account the
numerical issues associated with fixedpoint processors.
Chapter 18, Slide 10
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002
Implementation Issues
(1) The program runs on the DSK with the C6711 and
does not use any communication with the host.
(2) The scenary.h file is quite large (256x256 8-bit pixels
or 65536 bytes) and therefore needs to be located in a
specific memory location in the DSK. By using the
#pragma DATA_SECTION (…) directive the picture can
be located in the DRAM (origin address 0x0800 0000).
(3) For example, #pragma DATA_SECTION (image_in,
“ext_sdram”) allows the image_in data array to be
loaded into the section called “ext_sdram” which is
defined in the command file. The same applies to
image_out.
(4) The directory DSPCODE\DCT contains the entire
source and executable files required. The program
can be loaded into the DSK C6711 and by using the
display feature of the CCS as shown below the
contents of image_in and image_out can be displayed
and compared.
Chapter 18, Slide 11
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002
Implementation Issues
Graph properties for
image_in
image_in
Graph properties for
image_out
image_out
Chapter 18, Slide 12
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002
DCT Code and Links

Code location:


Projects:


Code\Chapter 18 - Discrete Cosine Transform\
Fixed Point in C:
\DCT_C_Fixed\
Links:

Chapter 18, Slide 13
\Links\Imaging Kit.pdf
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002
Chapter 18
Discrete Cosine Transform
- End -