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 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
Exercise 6a: Arithmetic Coding: (2) Provided Classes (see Git) class ProbModel: Adaptive Probability Model ProbModel # constructor (including initialization ) def __init__( self ): Binary Arithmetic Encoder ArithEncoder # initialization (p0=p1 =0.5) def init( self ) Binary Arithmetic Decoder ArithDecoder # functions for internal usage ... class ArithEncoder : class ArithDecoder : # constructor (uses OBitstream ) # constructor (uses IBitstream ) def __init__( self , bitstream ) def __init__( self , bitstream ) # encoding of bins # decoding of bins def encode( self , bin , probModel ) # adaptive def decode( self , probModel ) # adaptive def encodeEP( self , bin ) # bypass def decodeEP( self ) # bypass def encodeEPs( self , pattern , numBins ) # bypass def decodeEPs( self , numBins ) # bypass # finalization of arithmetic codeword # check for read errors def finalize( self ) # required at end! def success( self ) # general def finish( self ) # at end # estimation of required bits (without probModel update) def getEstBits ( self , bin , probModel ) # estimation of required bits (with probModel update) def getEstBitsUpdate ( self , bin , probModel ) Heiko Schwarz (Freie Universität Berlin) — Image and Video Coding
Exercise 6a: Arithmetic Coding: (3) Assignment of Adaptive Probabilities Use 8 Different Adaptive Probability Models (0..7) x/y for 4 × 4 blocks code for levels value codeword (s = sign) 0 coded block flag value codeword 0 0 0 0 X coordinate of last position ± 1 1 0 s 1 1 1 ± 2 1 1 1 s 2 1 0 0 1 first bin (indicating whether x > 0) ± 3 1 1 01 0 s 3 1 0 1 2 all bins of prefix part of mod. Exp-Golomb code ± 4 1 1 01 1 s ± 5 1 1 001 00 s Y coordinate of last position ± 6 1 1 001 01 s x/y for 8 × 8 blocks ± 7 1 1 001 10 s 3 first bin (indicating whether y > 0) ± 8 1 1 001 11 s value codeword ± 9 1 1 0001 000 s 4 all bins of prefix part of mod. Exp-Golomb code 0 0 ± 10 1 1 0001 001 s 1 1 1 ± 11 1 1 0001 010 s Values of quantization indexes 2 1 01 0 ± 12 1 1 0001 011 s 3 1 01 1 5 significance bin (indicating whether | q | > 0) ± 13 1 1 0001 100 s 4 1 00 00 ± 14 1 1 0001 101 s 6 greater-than-1 bin (indicating whether | q | > 1) 5 1 00 01 ± 15 1 1 0001 110 s 6 1 00 10 ± 16 1 1 0001 111 s 7 all bins of prefix part of Exp-Golomb code 7 1 00 11 ± 17 1 1 00001 0000 s ± 18 1 1 00001 0001 s · · · · · · All other bins (suffixes, sign) are coded in bypass mode Heiko Schwarz (Freie Universität Berlin) — Image and Video Coding
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
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) original transform coefficient t : � abs ( t ) � quantization index q : q = sign ( t ) · floor + f 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
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
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
Recommend
More recommend