Professional Documents
Culture Documents
and 1 if
1
1 1 2
,
n n
n n
d T T T T
l
l
. When binary thresholding is applied, testing the
position of d is reduced to a comparison of bits. If the paths are numbered starting
from 1 and at the p
th
path of the coefficients it is necessary to extract the (p+1)
th
bit
(starting from the left) from the binary expression of C.
(4) New threshold. We read or calculate the new threshold with
1
1 2
n
n
T T
l
=
l
,
for example. If the minimum threshold or the desired compression ratio is attained,
we stop; if not, we repeat stages 2, 3 and 4.
A.1.2. Example of application of the EZW algorithm (coding phase)
Let us consider the following simple example:
57 -35 52 8 5 12 -10 5
-29 25 14 -14 3 1 5 -2
15 15 2 -9 8 -10 6 12
-10 -6 -11 7 7 -2 4 5
-2 12 -1 47 6 6 -2 3
0 3 -2 1 1 -4 3 1
0 -4 8 -4 4 5 3 3
5 14 4 3 -2 5 -4 1
V1 D1
A3 H3
H2
H1
V3 D3
V2 D2
Appendix: The EZW Algorithm 315
(1) Initialization. Cmax = 57, thus
5
0
2 32 T T = = = .
(2) Principal stage. Path no. 1
A3 (1,1) = 57 > 32 gives the symbol P and 57 is placed on the secondary list
and replaced by a zero;
H3 (1,1) = 35 gives the symbol N since |35| > 32 and 35 is placed on the
secondary list and replaced by a zero;
V3 (1,1) = 29 gives Z because a child (V1 (1,4) = 47) is higher than the
threshold;
D3 (1,1) = 25 gives T because no child (in D2 and D1) is higher than the
threshold. It is thus useless to code D2 and D1.
Thus, [A3, H3, V3, D3] gives PNZT.
Continuing in a similar manner, H2 gives PTTT (P corresponds to the value
H2 (1,1) = 52), V2 gives TZTT (Z corresponds to the value V2 (1,2) = 15 since its
child V1 (1,4) = 47) and D2 is not coded since D3 is a zerotree). The coding process
continues and the complete code obtained is:
PNZT PTTT TZTT TTTT TPTT
At the end of this main stage, the secondary list contains the values [57 35 52 47].
(3) Secondary stage. Path no. 1
The elements of the secondary list are compared to the middle of the interval
[ , 2 ] T T = [32, 64], i.e. at 48. For the 1
st
path of the coefficients it is necessary to
extract the 2
nd
bit (starting from the left) from the binary expression of C.
produced code = 1 0 1 0
Secondary list
symbol binary 2
nd
bit
57 111001 1
35 100011 0
52 110100 1
47 101111 0
316 Wavelets and their Applications
After the first loop of the algorithm, the matrix of the coefficients (principal list)
thus becomes:
0 0 0 8 5 12 -10 5
-29 25 14 -14 3 1 5 -2
15 15 2 -9 8 -10 6 12
-10 -6 -11 7 7 -2 4 5
-2 12 -1 0 6 6 -2 3
0 3 -2 1 1 -4 3 1
0 -4 8 -4 4 5 3 3
5 14 4 3 -2 5 -4 1
(4) New threshold.
1
2
16 T T = = .
(5) Principal stage. Path no. 2
We obtain the codes ZTNPTTTTTTTT and the secondary list becomes:
[57 35 52 47 29 25].
(6) Secondary stage. Path no. 2
We compare (see section A.1.1 point 3) the elements [57 35 52 47 29 25] to 16.
We obtain 100111. They are the 3
rd
bits (starting from the left) of the binary
expressions.
(7) End of the algorithm.
The complete application of the coding phase of the algorithm in this example is
given below. It should be noted that the secondary stage (S6) is not present because
the threshold is already lower than 1.
(P1): PNZTPTTTTZTTTTTTTPTT
(S1): 1010
(P2): ZTNPTTTTTTTT
Appendix: The EZW Algorithm 317
(S2): 100111
(P3):ZZZZZPPNPPNZTNNTTPTTNTTTPNTTTPTTTPTTTTTTTTTPPTTTTTTTTTTT
(S3): 0011100111100010001110
(P4):ZZZZZZZZTTZNZTZPPTTTTPPTTTPTPTPPTNPTTNPTPPTNPPTPTTNT
(S4): 010100011111010101001011000110000001100000
(P5):ZZZZZZZTZZTZPZZZTTPTTTTNTTTNNTTPTTNTTTTPTTTTNPPTTTNTPPTT
(S5): 11011100011011000000000111110010100000011001000101011011
(P6): ZZZZZTTTTZTTZZTZTTTPNTTPTTPTTTTPTTTP
The sequence of codes [P1], [P1, S1], [P1, S1, P2], [P1, S1, P2, S2], etc.
constitutes a succession of increasingly precise quantized coefficient
approximations.
A.2. Decoding
A.2.1. Detailed description of the EZW algorithm (decoding phase)
The decoding phase consists of reversing the above stages.
(1) Initialization. Initialize the values of the coefficients by zeros, the list of
coefficients processed by an empty list and the threshold by
( )
l max
log2
0
2
C
T = .
(2) Principal stage. Read the codes of the principal list one by one. Each code is
one of the four symbols [P, N, Z, T]:
if the code is P, assign
n
T as the value of the coefficient and add the
coefficient (its position) to the list of processed coefficients;
if the code is N, assign
n
T as the value of the coefficient and add the
coefficient to the list of processed coefficients;
if the code is Z or T, do nothing.
(3) Secondary stage. Read the codes of the secondary list one by one. It
corresponds to the list of already processed coefficients. For each of these
coefficients, if the corresponding term of the secondary list is 0, do nothing, whereas
if this term is 1 modify its value. If the coefficient is positive,
1
1 2 n
T
is added to it
whereas if it is negative the same quantity is subtracted from it.
(4) New threshold. We read or calculate the new threshold with
1
1 2
n
n
T T
l
=
l
,
for example, and repeat stages 2, 3 and 4 until the list of codes is exhausted.
318 Wavelets and their Applications
A.2.2. Example of application of the EZW algorithm (decoding phase)
The decoding phase in the example used for coding gives:
A.3. Visualization on a real image of the algorithms decoding phase
In Figure A.1 we visualize some stages of the decoding phase on a real image in
order to progressively highlight the improvement of the resolution with decoding.
We decompose an image of size 64 u 64 at level 5 with the bior4.4 wavelet. The
grayscale image contains 255 levels, its storage thus requires 4,096 bytes. The EZW
algorithm uses 4 symbols for the principal stage and 2 for the secondary stage. After
its use, the effective coding of all the produced symbols notably reduces the
information to be stored or transmitted.
48 -32 48 0 0 0 0 0
-16 16 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 32 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
56 -32 48 0 0 0 0 0
-24 24 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 40 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
P1 + S1 + P2 P1 + S1 + P2 + S2
P1 P1 + S1
32 -32 32 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 32 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
48 -32 48 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 32 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Appendix: The EZW Algorithm 319
Figure A.1. EZW algorithm: at the top, the results after 1 and 3 iterations, at the bottom, the
results after 5, 7 and 9 iterations (number of code symbols 266, 2,160 and 8,179 respectively)
and at the bottom on the right is the original image
(P1)ZTPTTTT
T(S1) 0
(P1): ZTPTTTTT
(S1): 0
(P2): PPTPTTTTTTTT
(S2): 0111
(P3): TTTT
(S3): 0110