Signal Compression and JPEG
-
Upload
guest9006ab -
Category
Technology
-
view
2.930 -
download
1
description
Transcript of Signal Compression and JPEG
-1-
Overview
Sampling Fine Quantization
Transform Quantizer VLC encoding
A/D CONVERTER
COMPRESSION/SOURCE CODING
CHANNEL CODING
Error protect.Encipher
PCM encoded or “raw” signal(“wav”, “bmp”, …)
Compressed bit stream
(mp3, jpg, …)
Channel bit stream
Analog capturing
device(camera,
microphone)
-2-
Reduce the #Amplitudes
24 bit (16777200 different colors)
-3-
8 bit (256 different colors) CF 3
Reduce the #Amplitudes
-4-
6 bit (64 different colors) CF 4
Reduce the #Amplitudes
-5-
4 bit (16 different colors) CF 6
Reduce the #Amplitudes
-6-
1 bit (2 different colors) CF 24
Reduce the #Amplitudes
-7-
8 bit (256 different gray values) CF 3
Reduce the #Amplitudes
-8-
4 bit (16 different gray values) CF 6
Reduce the #Amplitudes
-9-
3 bit (8 different gray values) CF 8
Reduce the #Amplitudes
-10-
2 bit (4 different gray values) CF 12
Reduce the #Amplitudes
-11-
JPEG CF 15
But there are More Cleaver Ways
-12-
Why can Signals be Compressed?Because infinite accuracy of signal amplitudes is (perceptually) irrelevant
24 bit (16777200 different colors) 8 bit (256 different colors)Compression factor 3
Rate-distortion theory, scalar/vector quantization
-13-
Why can Signals be Compressed?Because signal amplitudes are statistically redundant
Information theory, Huffman coding
-14-
Why can Signals be Compressed?Because signal amplitudes are mutually dependent
0 500 1000 1500 2000 2500 3000 3500 4000 450050
100
150
200
250
“S”
0 1000 2000 3000 4000 5000100
150
200
“O”
Rate-distortion theory, transform coding
-15-
Why can Signals be Compressed?Example of signal with no dependencies between successive amplitudes (Gaussian uncorrelated noise)
Indeed “noise” compresses badly
-16-
System Overview
Sampling Fine Quantization
Transform Quantizer VLC encoding
A/D CONVERTER
COMPRESSION/SOURCE CODING
CHANNEL CODING
Error protect.Encipher
PCM encoded or “raw” signal(“wav”, “bmp”, …)
Compressed bit stream(mp3, jpg, …)
Channel bit stream
Analog capturingdevice(camera, microphone)
-17-
Quantization
p(x)
Q(x)
Quantizer level more probable
Even Uniform Odd Uniform
Even Non-uniform Odd Non-uniform
-18-
Information and Entropy
More ProbableLess information
-19-
Huffman Code
y4 0.51 0.51 (0) 0y3 0.20 0.29 (0) 0.49 (1) 11y2 0.14 0.15 (0) 0.20 (1) 101y5 0.08 0.08 (0) 0.14 (1) 1000y6 0.04 0.04 (0) 0.07 (1) 10010y1 0.02 0.02 (0) 0.03 (1) 100110y7 0.005 (0) 0.01 (1) 1001110y0 0.005 (1) 1001111
-20-
Run Length CodingRepresenting “0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 1 1 1 0 0 ...”“Runs” : 8 (“zeros”) 2 (“ones”) 6 (“zeros”) 5 (“ones”) ……The run lengths are also encoded (e.g. with Huffman coding)Efficient transforms (like DCT) used in compression produce
A lot of “zero” valuesAnd a “few” (significant) non-zero values
Typical symbol sequences to be coded “5 1 0 0 0 0 0 0 0 3 0 0 6 0 0 0 0 1 0 0 0 0 …..”
will be done by {zero-run, non-zero symbol/0} pairsHere: “{0,5},{0,1},{7,3},{2,6},{4,1},…..”The pairs will now be assigned a Huffman codeThis is used in JPEG
-21-
General Compression System
Sampling Fine Quantization
Transform Quantizer VLC encoding
A/D CONVERTER
COMPRESSION/SOURCE CODING
CHANNEL CODING
Error protect.Encipher
PCM encoded or “raw” signal(“wav”, “bmp”, …)
Compressed bit stream(mp3, jpg, …)
Channel bit stream
Analog capturingdevice(camera, microphone)
-22-
Correlation in Signals - IMeaningful signals are often highly predictable:
(Linear) Predictability has something to do with the autocorrelation function
0 500 1000 1500 2000 2500 3000 3500 4000 450050
100
150
200
2504
500 1000 1500 2000 2500 3000 3500 4000 4500100
0
100
Δx(n)=x(n)-x(n-1)
n
-23-
Principle of Differential PCM
- Q VLC
Previoussignal values (“past”)
x(n) Δx(n) 001010010Δx*(n)
Predict x(n)
)(ˆ nx
x(n-1), x(n-2), x(n-3), ….
-24-
Works Really Good - I
Variance = 3240
-25-
Works Really Good - II
Variance = 315
-26-
DPCM
Predicted signal
Signal to be encoded Prediction difference/error
Reconstructed signal
-27-
What Linear Predictor to Use?Examples:
PCM
Simple differences
Average last two samples
General linear predictor
$( )x n = 0
$( ) ~( )x n x n= −1
$( ) ~( ) ~( )x n h x n h x n= − + −1 21 2
$( ) ~( )x n h x n kkk
N
= −=∑
1
-28-
DPCM on Images
Same principle as 1-DDefinition of “Past”and “Future” in Images:
Predictions:horizontal (scan line)vertical (column)2-dimensional
-29-
General Compression System
Sampling Fine Quantization
Transform Quantizer VLC encoding
A/D CONVERTER
COMPRESSION/SOURCE CODING
CHANNEL CODING
Error protect.Encipher
PCM encoded or “raw” signal(“wav”, “bmp”, …)
Compressed bit stream(mp3, jpg, …)
Channel bit stream
Analog capturingdevice(camera, microphone)
-30-
Transform Coding
CorrelatingTransform
DecorrelatingTransform Q Q-1Vectorize
InverseVectorize
x(n) x θ $θ $x $( )x n
Which transform used?
T T-1channel
-31-
Removing Correlation - I
0 200 400 600 800 1000100
50
0
50
100
40 20 0 20 40
40
20
20
40
xx
1
2
⎛
⎝⎜
⎞
⎠⎟
x1
x2
-32-
Removing Correlation - II
0 200 400 600 800 1000100
50
0
50
100
xx
1
2
⎛
⎝⎜
⎞
⎠⎟
40 20 0 20 40
40
20
20
40
x1
x2
σ22
σ12
θ1
θ2
Rotate the coordinates
-33-
Removing Correlation - III
xx
1
2
⎛
⎝⎜
⎞
⎠⎟
x1
x2
0 100 200 300 400 500 600 700 800 90050
0
50
40 20 0 20 40
40
20
20
40
θ1
θ2
-34-
Decomposition
x t t t t= = + + +=∑ θ θ θ θk kk
N
N N1
1 1 2 2 L
t1
t8
0.707
0.25
-0.1250.00.00.063
-0.2-0.025
x
θ(Example)
3.1651.718
2.266
4.516
1.020
0.638
3.377
-0.702
θ
θ
k k n nn
N
n k n kk
N
t x k N
x t n N
= =
= =
=
=
∑
∑
,
,
, , ,
, , ,
1
1
1 2
1 2
K
K
θθ
θ=
⎛
⎝
⎜⎜⎜
⎞
⎠
⎟⎟⎟=
⎛
⎝
⎜⎜⎜
⎞
⎠
⎟⎟⎟
⎛
⎝
⎜⎜⎜
⎞
⎠
⎟⎟⎟=
1 11 1
1
1
M
L
M O M
L
M
N
N
N N N N
t t
t t
x
x
, ,
, ,
Tx
-35-
Discrete Cosine Transform
t1
t8
t2
t3
t4
t5
t6
t7
N=8
Tt =
0.354
0.354
0.354
0.354
0.354
0.354
0.354
0.354
0.49
0.416
0.278
0.098
0.098
0.278
0.416
0.49
0.462
0.191
0.191
0.462
0.462
0.191
0.191
0.462
0.416
0.098
0.49
0.278
0.278
0.49
0.098
0.416
0.354
0.354
0.354
0.354
0.354
0.354
0.354
0.354
0.278
0.49
0.098
0.416
0.416
0.098
0.49
0.278
0.191
0.462
0.462
0.191
0.191
0.462
0.462
0.191
0.098
0.278
0.416
0.49
0.49
0.416
0.278
0.098
(All picture compression standards implement this matrix in a clever way)
-36-
Image Transforms - I
6 0
4 6
1 1
1 1
1 -1
1 -1
1 1
-1 -1
1 -1
-1 14 1 -1 2=
t11 t12 t21 t22
θ11 θ12 θ21 θ22
xm n,
-37-
Basis Images for 2-D DCT
-38-
Discrete Cosine Transform (DCT) (1)
8 pixels
8 rows
-39-
Discrete Cosine Transform (DCT) (2)
Cosine patterns/DCT basis functions
64 pixels
-40-
Discrete Cosine Transform (DCT) (3)
Cosine patterns/DCT basis functions
64 pixels
89 8 8 1 0 -1 1 0
2 3 0 0 0 0 0 0
0 1 0 1 0 0 0 0
0 0 0 1 0 0 0 0
2 0 0 1 0 1 0 0
0 0 -1 1 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0
-41-
Discrete Cosine Transform (DCT) (4)
!
-42-
2-D DCT of Picture - I
-43-
2-D DCT of Image - II
A DCT coefficients isa weight of particularDCT basis function.
Low Low frequenciesfrequencies
High High frequenciesfrequencies
-44-
“Grouped” DCT Coefficients
-45-
JPEG Compression System
-46-
DCT Weight Matrix and QuantizationQuantization:
Recommended JPEG normalization matrix
$ [ ], ,,
',
θ θθ
k l k lk l
k lQ
Q N= =
⎛
⎝⎜⎜
⎞
⎠⎟⎟round
N k l, =
⎡
⎣
⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥
16 11 10 16 24 40 51 6112 12 14 19 26 58 60 5514 13 16 24 40 57 69 5614 17 22 29 51 87 80 6218 22 37 56 68 109 103 7724 35 55 64 81 104 113 9249 64 78 87 103 121 120 10172 92 95 98 112 100 103 99
-47-
User Controllable Quality
User has control over a “quality parameter” that runs from 100 (“perfect”) to 0 (“extremely poor”)
0 10 20 30 40 50 60 70 80 90 1000
1
2
3
4
5
6Q'
Q
Increasing quality
Par
amet
er u
sed
to s
cale
th
e no
rmal
izat
ion
mat
rix
-48-
Entropy coding
Huffman codedRunlength coding then huffman orarithmetic coding
-49-
Example
f k l, =
⎡
⎣
⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥
139 144 149 153 155 155 155 155144 151 153 156 159 156 156 156150 155 160 163 158 156 156 156159 161 162 160 160 159 159 159159 160 161 162 162 155 155 155161 161 161 161 160 157 157 157162 162 161 163 162 157 157 157162 162 161 161 163 158 158 158
θk l, =
− − − −− − − − − −− − − − −− −− − −
− −− − −− − − −
⎡
⎣
⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥
1260 1 12 5 2 2 3 123 17 6 3 3 0 0 111 9 2 2 0 1 1 07 2 0 1 1 0 0 01 1 1 2 0 1 1 1
2 0 2 0 1 1 1 11 0 0 1 0 2 1 13 2 4 2 2 1 1 0
DCT transform isexactly defined inJPEG standardaverage * 8
-50-
Example
$,θk l =
−− −− −
⎡
⎣
⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥
79 0 1 0 0 0 0 02 1 0 0 0 0 0 01 1 0 0 0 0 0 0
0 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 0
DC: Difference with quantized DC coefficient of previous block is Huffman encoded AC: Zig-zag scan coefficients, and convert to (zero run-length, amplitude) combinations:
(79) 0 -2 -1 -1 -1 0 0 -1 EOB{1,-2}{0,-1}{0,-1}{0,-1} {2,-1} EOB
Quantizationusing Q’ = 1
-51-
VLC Coding of AC CoefficientsThe (zero run-length, amplitudes) are put into categories
The (zero run-length, categories) are Huffman encodedThe sign and offset into a category are FLC encoded (required #bits = category number)
Category AC Coefficient Range1 -1,12 -3,-2,2,33 -7,...,-4,4,...,74 -15,...,-8,8,...,155 -31,...,-16,16,...,316 -63,...,-32,32,...,637 -127,...,-64,64,...,1278 -255,...,-128,128,...,2559 -511,...,-256,256,...,51110 -1023,...,-512,512,...,1023
-52-
JPEG AC Huffman TableZ ero R un C ategory C ode leng th C odeword
0 1 2 000 2 2 010 3 3 1000 4 4 10110 5 5 110100 6 6 1110000 7 7 1111000. . . .. . .1 1 4 11001 2 6 1110011 3 7 11110011 4 9 111110110. . . .. . . .2 1 5 110112 2 8 11111000. . . .. . . .3 1 6 1110103 2 9 111110111. . . .. . . .4 1 6 1110115 1 7 11110106 1 7 11110117 1 8 111110018 1 8 111110109 1 9 111111000
10 1 9 11111100111 1 9 111111010. . . .. . . .
E O B 4 1010
-53-
Example - III
The series {1,-2}{0,-1}{0,-1}{0,-1} {2,-1} EOBnow becomes
111001 01/00 0/00 0/00 0/11011 0/1010
Bit rate for AC coefficients in this DCT block 27 bits/64 pixels = 0.42 bit/pixel
-54-
Ordering of Coefficient
-55-
Sequential Encoding
-56-
AcknowledgementProf. Inald Lagendijk, Delft University of TechnologyAlso try the software VcDemo
http://ict.ewi.tudelft.nl/index.php?Itemid=124