Exercise 6a: Arithmetic Coding: (1) Overview syntax elements bins - - PowerPoint PPT Presentation

exercise 6a arithmetic coding 1 overview
SMART_READER_LITE
LIVE PREVIEW

Exercise 6a: Arithmetic Coding: (1) Overview syntax elements bins - - PowerPoint PPT Presentation

Exercise 6a: Arithmetic Coding: (1) Overview syntax elements bins bits entropy encoder binary arithmetic bitstream (codeword tables) coding engine probability model Goal : Integrate adaptive binary arithmetic coding for improving entropy


slide-1
SLIDE 1

Exercise 6a: Arithmetic Coding: (1) Overview

binary arithmetic coding engine entropy encoder (codeword tables) syntax elements bins probability model bits bitstream

Goal: Integrate adaptive binary arithmetic coding for improving entropy coding Main Changes Bits of codewords are not directly written to bitstream Bins are processed by binary arithmetic coding engine (which writes final codeword) Adaptive Binary Arithmetic Coding Use arithmetic coding engine from video coding standards H.264/AVC and H.265/HEVC Binary arithmetic coding with 2 modes:

1 Regular mode:

Adaptive probability models (probabilities are automatically adjusted)

2 Bypass mode:

Fixed probabilities p(0) = p(1) = 0.5

Heiko Schwarz (Freie Universität Berlin) — Image and Video Coding

slide-2
SLIDE 2

Exercise 6a: Arithmetic Coding: (2) Provided Classes (see Git)

Adaptive Probability Model ProbModel Binary Arithmetic Encoder ArithEncoder Binary Arithmetic Decoder ArithDecoder

class ProbModel: # constructor (including initialization ) def __init__( self ): # initialization (p0=p1 =0.5) def init( self ) # functions for internal usage ... class ArithEncoder : # constructor (uses OBitstream ) def __init__( self , bitstream ) # encoding

  • f bins

def encode( self , bin , probModel ) # adaptive def encodeEP( self , bin ) # bypass def encodeEPs( self , pattern , numBins ) # bypass # finalization

  • f

arithmetic codeword def finalize( self ) # required at end! # estimation

  • f

required bits (without probModel update) def getEstBits ( self , bin , probModel ) # estimation

  • f

required bits (with probModel update) def getEstBitsUpdate ( self , bin , probModel ) class ArithDecoder : # constructor (uses IBitstream ) def __init__( self , bitstream ) # decoding

  • f bins

def decode( self , probModel ) # adaptive def decodeEP( self ) # bypass def decodeEPs( self , numBins ) # bypass # check for read errors def success( self ) # general def finish( self ) # at end

Heiko Schwarz (Freie Universität Berlin) — Image and Video Coding

slide-3
SLIDE 3

Exercise 6a: Arithmetic Coding: (3) Assignment of Adaptive Probabilities

Use 8 Different Adaptive Probability Models (0..7)

0 coded block flag

X coordinate of last position

1 first bin (indicating whether x > 0) 2 all bins of prefix part of mod. Exp-Golomb code

Y coordinate of last position

3 first bin (indicating whether y > 0) 4 all bins of prefix part of mod. Exp-Golomb code

Values of quantization indexes

5 significance bin (indicating whether |q| > 0) 6 greater-than-1 bin (indicating whether |q| > 1) 7 all bins of prefix part of Exp-Golomb code

All other bins (suffixes, sign) are coded in bypass mode

x/y for 4×4 blocks value codeword 1 1 1 2 1 0 0 3 1 0 1 x/y for 8×8 blocks value codeword 1 1 1 2 1 01 0 3 1 01 1 4 1 00 00 5 1 00 01 6 1 00 10 7 1 00 11 code for levels value codeword (s = sign) ±1 1 0 s ±2 1 1 1 s ±3 1 1 01 0 s ±4 1 1 01 1 s ±5 1 1 001 00 s ±6 1 1 001 01 s ±7 1 1 001 10 s ±8 1 1 001 11 s ±9 1 1 0001 000 s ±10 1 1 0001 001 s ±11 1 1 0001 010 s ±12 1 1 0001 011 s ±13 1 1 0001 100 s ±14 1 1 0001 101 s ±15 1 1 0001 110 s ±16 1 1 0001 111 s ±17 1 1 00001 0000 s ±18 1 1 00001 0001 s · · · · · ·

Heiko Schwarz (Freie Universität Berlin) — Image and Video Coding

slide-4
SLIDE 4

Exercise 6a: Arithmetic Coding: (4) Suggested Integration Steps

1 Replace Writing/Reading of Bits with Arithmetic Coding in Bypass Mode (≈ same efficiency)

Encoder:

Construct ArithEncoder after writing bitstream header Replace all OBitstream::addBit[s](.) with ArithEncoder::encodeEP[s](.) Call ArithEncoder::finish() at end of picture

Decoder:

Construct ArithDecoder after reading bitstream header Replace all IBitstream::getBit[s](.) with ArithDecoder::decodeEP[s](.) At end of entropy decoding: Check success by calling ArithDecoder::finish()

2 Successively Replace Bypass with Adaptive Coding for Individual Bins (see previous slide)

Maintain array of 8 probability models (ProbModel) in entropy encoder and decoder Replace bypass coding with adaptive arithmetic coding for individual bins (one after the other)

Encoder: Replace encodeEP[s](.) with encode(.) using the correct probability model Decoder: Replace decodeEP[s](.) with decode(.) using the correct probability model

After modifying coding for each individual bin

Check whether encoding/decoding works correctly (PSNR shall not change) Check whether bitstream size is reduced

Heiko Schwarz (Freie Universität Berlin) — Image and Video Coding

slide-5
SLIDE 5

Exercise 6b: Improved Quantization

Goal: Improve Selection of Quantization Indexes in Encoder Implement and Test Quantization Improvement Implement the following quantization rule in the encoder (note: decoder is not modified) q = sign(t) · floor abs(t) ∆ + f

  • t :
  • riginal transform coefficient

q : quantization index ∆ : quantization step size f : fixed rounding offset (0..0.5)

Test different rounding offsets (based on 2-3 example images)

Vary the rounding offset f in the range from 0 to 0.5 (e.g., in steps of 0.05) Measure rate-PSNR curves (QPs = 8, 12, 16, 20, 24, 28) for each rounding offset f Compare rate-PSNR curves for the different rounding offsets f

Select a suitable value for the rounding offset f based on the coding experiments Note: It would make sense to run the experiments after the integration of arithmetic coding

Heiko Schwarz (Freie Universität Berlin) — Image and Video Coding

slide-6
SLIDE 6

Exercise 6c: Integration and Testing

Integration Adaptive binary arithmetic coding (exercise 6a) Quantization with rounding offset (exercise 6b) Testing of Coding Efficiency Select at least 3 different test images Generate rate-PSNR curves by running codec

with default block size (16×16) and different QP values {8, 12, 16, 20, 24, 28} and measure rate and PSNR (using PSNR tool)

Evaluation of Coding Tools Generate curves for:

1 Last version (before integration of new tools) 2 After integration of arithmetic coding 3 After integration of arithmetic coding and improved quantization

Compare curves to JPEG (see data in git repository)

Heiko Schwarz (Freie Universität Berlin) — Image and Video Coding

slide-7
SLIDE 7

Exercise 6d: Preparation for Next Exercises (Mode Decision)

Goal: Implement a function for estimating the number of bits that would be written for a block Implementation (encoder only) Function should return the total number of bits that would be written for a block

the bitstream must not be modified actual entropy coding (incl. arithmetic coding) for the block should be taken into account

Total number of bits can be estimated as follows:

Each bypass coded bin produces 1 bit The bits for a regular coded bin can be estimated using ArithEncoder::getEstBits( probModel )

Testing the Implementation Verify that calling the function does not result in a different bitstream Use the implemented function for estimating the total number of bits written for an image (function calls have to be interleaved with the actual entropy coding for the blocks) Compare that number to the size of the bitstream (without header) — should be similar

Heiko Schwarz (Freie Universität Berlin) — Image and Video Coding