Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
energy compaction
is the ability to pack the energy of the spatial sequence into as few frequency q y coefficients as p possible this is very important for image compression we represent the signal in the frequency domain if compaction is high high, we only have to transmit a few coefficients instead of the whole set of pixels
Image compression
an image compression system has three main blocks
each tries to throw away information which is not g , but costs bits essential to understand the image,
4
Image compression
the transform throws away correlations
if you make a plot of the value of a pixel as a function of one of its neighbors
you will see that the pixels are highly correlated (i.e. most of the time they are very similar) this is j just a consequence q of the fact that surfaces are smooth
5
Image compression
the transform eliminates these correlations
this is best seen by considering the 2-pt transform note that the first coefficient is always the DC-value
X = Tx,
i.e. T has orthogonal columns this means that
T TT = I
Image compression
the transform eliminates these correlations
note that if x[0] similar to x[1], the
T TT = I
applies a rotation to the pixel space this aligns the data with the canonical axes
7
Image compression
a second advantage of working in the frequency domain
is that our visual system is less sensitive to distortion around edges the transition associated with the edge masks our ability to perceive the noise e.g. if you blow up a compressed picture, it is likely to look like this in general, the compression errors are more annoying in the smooth image regions
8
Image compression
three JPEG examples
36KB
5.7KB
1.7KB
Image compression
important point: by itself, the transform
does not save any bits does not introduce any distortion
both of these happen when we throw away information this is called lossy lossy compression compression and implemented by the quantizer what is a quantizer?
think of the round() function, that rounds to the nearest integer round(1) = 1; round(0.55543) = 1; round (0.0000005) = 0 instead of an infinite range between 0 and 1 (infinite number of bits to transmit) the output is zero or one (1 bit) we threw away all the stuff in between between, but saved a lot of bits a quantizer does this less drastically
10
Quantizer
it is a function of this type
inputs in a given range are mapped to the same output o tp t
to implement this, we
1) ) define a q quantizer step p size Q 2) apply a rounding function
x xq = round Q
the larger g the Q, the less reconstruction levels we have more compression at the cost of larger distortion e.g. for x in [0,255], we need 8 bits and have 256 color values with Q = 64 64, we only have 4 levels and only need 2 bits
11
Quantizer
note that we can quantize some frequency coefficients more heavily than others by simply increasing Q this leads to the idea of a quantization matrix we start with an image block (e.g. 8x8 pixels)
12
Quantizer
next we apply a transform (e.g. 8x8 DCT)
DCT
13
Quantizer
and quantize with a varying Q
DCT
Q mtx
14
Quantizer
note that higher frequencies are quantized more heavily
Q mtx increasing frequency
in result result, many high frequency coefficients are simply wiped out
DCT quantized DCT
15
Quantizer
this saves a lot of bits, but we no longer have an exact replica of original image block
DCT quantized DCT
inverse DCT
original pixels
16
Quantizer
note, however, that visually the blocks are not very different
original i i l d decompressed d
we have saved lots of f bits without much perceptual loss this is the reason why JPEG and MPEG work
17
Image compression
three JPEG examples
36KB
5.7KB
1.7KB
note that the two images on the left look identical JPEG requires 6x less bits
18
N 1 k (2n + 1) , 0 k < N 2 x[n]cos C x [k ] = n =0 2N 0 otherwise 1 N 1 w[k ]C x [k ]cos k (2n + 1) 0 n < N x[n] = N k =0 2N otherwise 0
20
from this equation we can immediately see that the DCT coefficients are real to understand the better energy compaction
it is interesting to compare the DCT to the DFT it turns out that there is a simple relationship
we consider a sequence x[n] which is zero outside of {0, , N-1} to relate DCT to DFT we need three steps
21
y[n]e
2 kn 2N
0 k < 2N
2 N 1 n= N
y[n]e
2 kn 2N
22
2 N 1 n= N
x[2 N n 1]e
N 1 j
2 kn 2N
= (m = 2 N 1 n, n = 2 N 1 m ) = = x[n]e
N 1 j 2 kn 2N
+ x[m]e
m =0
2 k ( 2 N 1 m ) 2N
2 2 2 2 kn j kn j k 2N j k j2 2N N 2N 2N = x[n]e +e e 1 4 24 3e n =0 1 2 2 2 kn j kn j k j2 2N N 2N = x[n]e +e e n =0 N 1
23
= x[n ]e
n =0 N 1 n =0 j
N 1
2N
2 2 k kn j k j kn j j2 N 2N 2N 2N e +e e e k
= 2 x[n ]e =e
2N k N 1
2N
cos k ( 2n + 1) 2N
2 x [ n ] cos k ( 2 n + 1 ) 2N n =0
j
from which
Y [k ] = e
2N
C x [k ],
0 k < 2N
24
x[n] { y[n] {
N pt 2 N pt
DFT
[k ] C Y x [k ] { 1 2 3
2 N pt N pt
Energy compaction
x[n] { y[n] {
N pt 2 N pt DFT
[k ] C Y x [k ] { 1 2 3
2 N pt N pt
next we remember that the DFT is identical to the DFS of the periodic extension of the sequence lets look at the periodic extensions for the two cases
when transform is DFT: we work with extension of x[n] when transform is DCT: we work with extension of y[n]
26
Energy compaction
x[n] { y[n] {
N pt 2 N pt DFT
[k ] C Y x [k ] { 1 2 3
2 N pt N pt
note that in the DFT case the extension introduces discontinuities this does not happen for the DCT, due to the symmetry of y[n] the elimination of this artificial discontinuity, which contains a lot of high frequencies, frequencies is the reason why the DCT is much more efficient
27
Fast algorithms
the interpretation of the DCT as
x[n] { y[n] {
N pt 2 N pt
DFT
[k ] C Y x [k ] { 1 2 3
2 N pt N pt
also gives us a fast algorithm for its computation it consists exactly of the three steps 1) y[n] = x[n]+x[2N-1-n] 2) Y[k] = DFT{y[n]} this can be computed with a 2N-pt FFT 3) j k
C x [k ] = e
2N
Y [k ], 0 k < N 0, otherwise
28
2D DCT
the extension to 2D is trivial the procedure is the same
x[n1 , n2 ] y[n1 , n2 ] 1 4 2 4 3 1 4 2 4 3
N1 N 2 p pt pt 2 N1 2 N 2 p
2D DFT
pt 2 N1 2 N 2 p
Y [k1 , k 2 ] C x [k1 , k 2 ] 1 4 2 4 3 1 4 24 3
N1 N 2 p pt
with
+ x[n1 ,2 N 2 1 n2 ] + x[2 N1 1 n1 ,2 N 2 1 n2 ]
29
2D DCT
the end result is the 2D DCT pair
N 1 1N 2 1 0 k1 < N 1 , cos 4x [n1 , n 2 ]cos k ( 2 n + 1 ) k ( 2 n + 1 ) 2 2N 1 1 2N 2 C x [k 1 , k 2 ] = n1 =0 n 2 =0 0 k2 < N2 1 2 otherwise 0 1 N 1 1N 2 1 0 n1 < N 1 [ ] w [ k ] w [ k ] C k , k cos k ( 2 n + 1 ) cos k ( 2 n + 1 ) 1 1 2 2 x 1 2 2N 1 1 2 2 x [n1 , n 2 ] = N 1N 2 k 1 2N 2 0 n2 < N 2 1 =0 k 2 =0 0 otherwise
with
k1 = 0 1 , , w1 [k1 ] = 2 1, 1 k1 < N1 k2 = 0 1 , w2 [k 2 ] = 2 1, 1 k 2 < N 2
it is possible to show that the 2DCT can be computed p (homework) ( ) with the row-column decomposition
30
2D-DCT
1) create intermediate sequence by computing 1D-DCT of rows 2) compute 1D-DCT of columns
n2 n2
1D-DCT
n1
k1
x [ n1 , n 2 ]
n2 k2
f [ k1 , n 2 ]
1D-DCT 1D DCT
k1
k1
f [k1 , n 2 ]
C x [k1 , k 2 ]
31
32