The Embedded Block Coding with Optimized Truncation in JPEG2000

advertisement
The Embedded Block Coding with Optimized Truncation
in JPEG2000
蘇文鈺
Prepared By 黃文彬
成大資訊
JPEG2000 Codec
Source
Image Data
Forward
Wavelet
Transform
Quantization
Coefficient
bit
modeling
Arithmetic
encoding
Compressed
Image Data
Inverse
Wavelet
Transform
Reconstructed
Image Data
(a) encoder
Compressed
Image Data
Arithmetic
decoding
Coefficient
bit
modeling
DeQuantization
(b) decoder
Wavelet Compression
Level 2
Wavelet Image
Original Image
Wavelet Image
Quantization
120 128 130 105 78 23
150 10 218 89 12 45
98 104 38 204 239 89
78 198 19 178 192 37
109 45 23 106 76 12
…..
…..
28 120 238 129 109 37
...
...
...
…
…
129
110
98
123
67
… 203
Pixel Representation
DWT
...
DWT
9283
8785
456
148
103
10
-986 49 40 19
2083 29 -38 61
108 23 37 31
51 29 -36 45
22 20 12 -19
……
……
2
0 -3 -7 11
5721
3061
-440
621
70
… 0
… -3
… 1
… -2
… 4
… 0
Wavelet Coefficients
3
5
6
8
3
1 -16 9 10
3 3 0 0
-2 18 0 0
1 1 0 0
12 0 0 0
……
……
0 0 0 -0 -0
0
1
0
5
0
…
…
…
…
…
0
-0
0
-0
0
0 … 0
SPIHT Algorithm For Wavelet Compression
Zero-tree Encoding
Rough Image
File Structure
Header
Rough Image
A Zero-tree
Sequence of
Zero-trees
The JPEG2000 Encoder
Block of
sub-band samples
Embedded block
T1
Embedded Block Coding
bit-streams
Operates on block samples
The part of EBCOT
T2
Full-featured
Coding of block contributions
bit-stream
To each quality layer
Operates on block summary info
Quantization

The quantization operation is defined by the step
size parameter,  b ,through
 yb n 
qb n  sign  yb n


b




Here, yb n denotes the samples of sub-band b,
while qb n denotes their quantization indices.
The step size for each sub-band is specified in
terms of an exponent,  b , and a mantissa,  b ,
where
 b  0  b  211
 b 
b  2
1  11 
 2 
0   b  25
LL
HL
HL
LH
HH
HL
LH
HH
LH
HH
From “Sub band” to “code block” to “bit stream”
EBCOT Layered Formation
The Concept of EBCOT


Sub-Block Significance Coding
Bit-Plan Coding Primitives





Fractional Bit-Planes and Scanning Order




Zero Coding
Run Length Coding
Sign Coding
Magnitude Refinement Coding
Significance Propagation Pass
Magnitude Refinement Pass
Cleanup Pass
Layer Formation and Representation


Packet Header Coding
Packet Body Coding
Sub-bank and Code Block and sub-block



Generally, Code Block size is 64*64 or 32*32
and sub-code block size is 16*16.
The scanning order of the sub block to be
used.
Each code block is coded independently.
Code Block
Code Sub-Block
LL
HL
HL
LH
HH
HL
LH
HH
LH
HH
Significant



Significance:當一個係數bit-plane 的值,第一次由0變為1,則此
時這個係數將變為Significance。
Refinement:當一個係數已經是Significance,則這個係數接下來的
bit皆稱之為Refinement。
Sign:即係數的符號值。
The Bit Plan Coding Primitives
Scan coding
sign
-2
1000010
11
0001011
0
0000000
-23
1010111
49
0110001
Bit plan 4
3
0000011
Bit plan 5
-10
1001010
Bit plan 1
Bit plan 2
Bit plan 3
Bit plan 6
q = -2
11
0
-23
49
3
-10
Four Types of Coding Operation for Bit Plan Coding

Zero Coding


Run Length Coding


Reduce the average number of symbols needed to be coded.
Sign Coding


Used to code new significance.
Used to code the sign right after a coefficient is identified
significant.
Magnitude Refinement Coding

3 context depending on the significance of its neighbors
and whether it is the first time for refinement.
stripe
Stripe Oriented Scanning Pattern Followed Within Each Coding Pass
Context window
Code block width J2
Zero Coding

The objective here is to code
, given that
Run Length Coding

Specifically, each of the following conditions must hold:

1) Four consecutive samples must all be insignificant, i.e.,

2) The samples must have insignificant neighbors, i.e.,

3) The samples must reside within the same sub-block
4) The horizontal index of the first sample,
, must be even.

0
0
1
0
0
0
0
0
1
0
0
0
Example for RLC
Sign Coding

當symbol由insignificance 變為significance,此時必須將送出該
symbol 的sign值,而sign 值是由垂直及水平鄰近點的sign 值和
significance 來查表決定context states。
 h  jm ,n     jm ,n 1   jm ,n 1     jm ,n 1   jm ,n 1 
 v  jm ,n     jm 1,n   jm 1,n     jm 1,n   jm 1,n 

  
x  j   sign x  j min 1, x  j 
x h  j   sign x h  j  min 1, x h  j 
v
v
v
symbolk   0 xk  xˆk   1
symbolk   1 xk  xˆk   1
Magnitude Refinement Coding

Specifically,
is coded with context 0 if
with context 1 if
and
and with context 2 if
,
Three Coding Pass
The JPEG2000 standard other three pass

Significance Propagation Pass

Magnitude Refinement Pass

Cleanup Pass
Significance Propagation Pass


The coding pass for each bit plane is the significance pass.
This pass is used to convey significance and (as necessary) sign
information for samples that have not yet been found to be significant
and are predicted to become significant during the processing of the
current bit plane.
Magnitude Refinement Pass


During this pass we skip over all samples except those which are
already significant, and for which no information has been coded in the
previous two passes.
These samples are processed with the MR primitive.
Cleanup Pass


Here we code the least significant bit, of all samples not
considered in the previous two coding passes, using the SC
and RLC primitives as appropriate
if a sample is found to be significant in this process, its sign
is coded immediately using the SC primitive.
Cleanup Pass Algorithm(cont.)
The EBCOT encoding procedures

Algorithm for encoder
Initialize the MQ encoder
Initialize the context states according to each coding table
tmp
Set v  0
For each j  [0, j0 )  [0, j1 )
Initialize all the variable
For p  K  1,....,1,0
If p  K  1
Perform Encoder-Pass0 (Significance propagation pass)
Perform Encoder-Pass1 (Magnitude refinement pass)
Perform Encoder-Pass2 (Cleanup pass)
A Simple Example For Bit Plan Coding
Example :
10 = +1010
1 = +0001
3 = +0011
-7 = -0111
bit plane1
bit plane2
bit plane3
bit plane4
1
0
1
0
0
0
0
1
0
0
1
1
0
1
1
1
Block diagram of the embedded block coder
Code block
sample array
v j ,   j 
Significance
state
Delayed
significance
First pass
membership
  j
  j
  j
Context Adaptive
Bit Plane Coder
Context state file
 Sk
k
x
k
MQ coder
Embedded bit
stream
EBCOT Decoder

Algorithm for decoder
Initialize the context states according to each coding table
For each j  [0, j0 )  [0, j1 )
Initialize all the variable
For p  K  1,....,1,0
If p  K  1
Perform De-Significance propagation pass
Perform De-Magnitude refinement pass
Perform De-Cleanup pass
Redefine JPEG2000 Table
 m, n
h v
Context
1
x
12 / 0xC
hi k 
vi k 
0
1
11 / 0xB
0
0
0
0
0
10 / 0xA
0
0
LL, LH, HL Sub-bank
HH Sub-bank
d i k  Context
d i k 
hi k   vi k 
Context
1
0
0
1
1
2
0
1
2
h
v
x̂
Context
0
0
>1
3
0
>1
3
1
1
1
17 / 11
0
1
x
4
1
0
4
1
0
1
16 / 10
0
2
x
5
1
1
5
1
-1
1
15 / F
1
0
0
6
1
>1
6
0
1
1
14 / E
0
0
1
13 / D
1
0
>0
7
2
0
7
0
-1
-1
14 / E
1
>0
x
8
2
>0
8
-1
1
-1
15 / F
2
x
x
9
>2
x
9
-1
0
-1
16 / 10
-1
-1
-1
17 / 11
Context label in RLC: RLC(0),UNIFORM(18/0x1D)
Example 1 For JPEG2000 Encoder(Only Cleanup Pass)
Example 1 For JPEG2000 Decoder (Only Cleanup Pass)


第一個讀入的值為context label
即coding的方式,查表可知00為
Run-length coding.
第二個讀入的值為symbol即本身
的二進位值,此例為1
Example 2 For JPEG2000- Two Bit Plane
Example 2 For JPEG2000 – Bit Plane 1 Cleanup Pass (1)
Example 2 For JPEG2000 – Bit Plane 1 Cleanup Pass (2)
Example 2 For JPEG2000 – Bit Plane 2 Significance Pass (1)
Example 2 For JPEG2000 – Bit Plane 2 Significance Pass (2)
Example 2 For JPEG2000 – Bit Plane 2 Magnitude Refinement Pass
Example 2 For JPEG2000 – Bit Plane 2 Cleanup Pass (1)
Arithmetic Coding - MQ Coder



Before talking about MQ coder, we must understand the
Arithmetic coding.
Because the MQ coder is almost the same as a binary
arithmetic coding.
Just only one difference between them.




Where is the probability of the zero or one from?
For binary arithmetic coding, the probability of zero or one is
driven by the pre-processing.
In other words, before arithmetic coding, the probability of zero
or one have been already known, and it’s through the statistic of
all data.
In MQ coder, the probability of zero or one is by the dynamic
decision.
Arithmetic Coding - MQ Coder






In JPEG2000 standard, there is a table for MQ coder.
The table provides the new probability of zero or one.
The table is shown in the next page.
In the beginning, the probability of zero or one is 0.5, and it is
the start of table.
And the next probability of zero or one depends on the input
context that is zero or one.
If the input context is zero, the new probability of zero becomes
larger in the table. Otherwise, it becomes smaller.
Arithmetic Coding - MQ Coder
Arithmetic Coding - MQ Coder
Arithmetic Coding - MQ Coder
Arithmetic Coding - MQ Coder
Arithmetic Coding – Binary Arithmetic Coding Algorithm
Initialize
N
C  0 , A  2, r  1, b  0
For each n  0,1,.....
Set T  Ap0,n
If xn  1
C  CP T
T  2 AT
If C  2 N  P
Propagate carry
While T  2 N  P 1
Renormalize
Set An 1  2  P T 
xn
p0, n
Binary
arithmetic coder
Arithmetic codestream
Arithmetic Coding – Binary Arithmetic Coding Algorithm
Propagate carry
Emit-bit(1)
If r  0 ,
execute r  1
Set r  0
Else
Set r  1
Renormalize
Increment b  b  1
Shift T  2T
Shift C  2C
times, emit-bit(0)
If C  2 N  P
if r  0 ,
emit-bit(1)
else
increment r  r  1
Else
if r  0
emit-bit(0)
execute r times,emit-bit(1)
Set r  0
Arithmetic Coding - MQ Coder algorithm
C 0 , A2
Initialize
For each n  0,1,.....
s  sn and P  P kn 
N
A  A  Pn
If A  Pn
s 1  s
If xn  s (encode an MPS)
C  C  pn
else (encode an LPS)
A  pn
If A  2 N 1
If xn  sn (The symbol was a real MPS)
kn  NMPS (kn )
else (The symbol was a real LPS)
sn  sn  switch(kn )
While A  2 N 1
renormalization
kn  NLPS (kn )
Arithmetic Coding - MQ Coder Example


We want to encode 1101 and the coding pass is always in
context 1
(1)

Initial
 A = 0x8000 , C = 0x0000 , k = 0 , B = 0 , ct = 12 , Sn
=0

Encode 1
 X = 1 , Sn = 0 , k = 0
 P = 5601 , A = A – P = 29ff
 A(29ff) < P(5601) => S = 1 – Sn = 1
 X = S => C = C + P = 5601
 A(29ff) < 0x8000 and X != Sn => Sn = 1 and k = 1
 A = a7fc , C = 15804 , ct = 10
While A < 0x8000
A = 2A , C = 2C , ct = ct -1
if ct = 0
Transfer-Byte
Arithmetic Coding - MQ Coder Example


Encode 1
 X = 1 , Sn = 1 , k = 1
 P = 3401 , A = A – P = 73fb
 A(73fb) > P(3401)
 X = S => C = C + P = 15804 + 3401 = 18c05
 A(73fb) < 0x8000 and X = Sn => k = 2
 A = e7f6 , C = 3180A , ct = 9
Encode 0
 X = 0 , Sn = 1 , k = 2
 P = 1801 , A = A – P = cff5
 A(cff5) > P(1801)
 X != S => A = 1801
 A(1801) < 0x8000 and X != Sn => Sn = 1 and k = 9
 A = c008 , C = 18c050 , ct = 6
Arithmetic Coding - MQ Coder Example

Encode 1
 X = 1 , Sn = 1 , k = 9
 P = 3801 , A = A – P = 8807
 A(8807) > P(3801)
 X = S => C = C + P = 18c050 + 3801 = 18f851
 A(18f851) > 0x8000 and X != Sn => Sn = 1 and k = 9
 A = c008 , C = 18c050 , ct = 6
Combined EBCOT with MQ Coder
Encoder-Pass0 Procedure (significance propagation) Algorithm
For each location, j, following the stripe-based scan of above figure
if   j   0 and k sig  j   0 ,
p
sig
MQ-Encode( x  v  j  , k  k  j  )
If v p  j   1 ,
  j 1
  j  1
else
  j  0
Encode-Sign(
  j ,  h  j ,  v  j  )
Combined EBCOT with MQ Coder
Encode-Sign Procedure Algorithm
flip
v
h
sign
Determine k
and 
from   j  and   j  using Table 2
If   j   flip  1
,
MQ-Encode( x  0 , k  k sign )
 flip
 h  j
 v  j
k sign
Else
1
1
14
1
MQ-Encode( x  1 , k  k sign )
1
0
13
1
1
-1
12
1
0
1
11
1
0
0
10
1
0
-1
11
-1
-1
1
12
-1
-1
0
13
-1
-1
-1
14
-1
Combined EBCOT with MQ Coder
Encoder-Pass1 Procedure (magnitude refinement) Algorithm
For each location, j, following the stripe-based scan of above Figure
If   j   1 and   j   0 ,

mag
Find k
form   j  and k sig  j  using table3
MQ-Encode( x  v p  j  , k  k mag )

  j    j

  j
k sig  j  k map
0
0
15
0
>0
16
1
xa
17
Combined EBCOT with MQ Coder
Encoder-Pass2 Procedure (cleanup) Algorithm
For each location, j, following the stripe-based scan of above Figure
if j1 mod 4  0 and j1  J1  4 ,(entering a full stripe column)
r  1 (signifies not using run mode)
sig
if k  j1  i, j2   0 for all i  0,1,2,3 ,(enter run mode)
r 0
while r  4 and v p  j1  r , j2   0 ,
r  r 1
if r  4
else
MQ-Encode( x  0, k  k )
(run interruption)
MQ-Encode( x  1, k  k run )
MQ-Encode( x   r , k  k uni
run
 2 
MQ-Encode( x  r mod 2, k  k uni
)
)
Combined EBCOT with MQ Coder (cleanup pass cont.)
If
  j   0 and   j   0 ,
if r  0 ,
r  r 1
(no need to code significance)
else
if
MQ-Encode( x  v
v p  j  1 ,
p
 j , k  k sig  j 
  j 1
h
v
Encode-Sign(   j ,   j ,   j  )
)
Download