Exercise 4a: Padding of Input Image Main Goal : The image codec should work with all combinations of sizes and block sizes Encoder s [ x , y ] = s [ W − 1 , y ] Header: Original image size W × H and block size B Calculate image dimension W ′ × H ′ used for coding Both W ′ and H ′ are multiples of block size B Fill missing samples with suitable values Suggestion: Constant border extension (see figure) Decoder Read image size W × H and block size B from header Calculate image dimension W ′ × H ′ used for coding Remove added samples before outputting the reconstructed image of size W × H s [ x , y ] = s [ x , H − 1 ] Heiko Schwarz (Freie Universität Berlin) — Image and Video Coding
Exercise 4b: Discrete Cosine Transform (DCT-II) Goal: Implement forward and inverse transform # ----- discrete cosine transform ----- Separable DCT-II for specified block size class Transform: Verify implementation: # constructor : # - create transform matrices for Successive application of DCT and inverse DCT # DCT -II of given block size def __init__( self , blockSize ): should yield original block of samples ... [ very small errors (PSNR > 80 dB) might occur ] # Forward transform: # - apply separable DCT -II to given # block of samples (integers) Encoder # - return block of transform # coefficients (floating -point values) Apply separable DCT-II to each block of samples def dct( self , sampleBlock ): ... Block of transform coefficients (floating-point) # Inverse transform: # - apply separable inverse DCT -II # to block of transform coefficients Decoder # - round result to closest integer # - return reconstructed block Apply separable IDCT-II to block of coefficients # of samples (integer values) def idct( self , transformBlock ): Includes rounding to closest integer ... Reconstructed block of samples (integer) Heiko Schwarz (Freie Universität Berlin) — Image and Video Coding
Exercise 4c: Scalar Quantization (first version) Goal: Implement scalar quantization # ----- uniform reconstruction quantizer ----- Uniform Reconstruction Quantizer (URQ) class Quantization : with simple rounding at encoder side # constructor : # - calculate quantization step size def __init__( self , QP ): Quantization Parameter QP ... Integer value controlling strength of quantization # Quantization (simple version ): # - divide transform coefficients (float) Add as optional command line parameter # by quantization step size (float) # - round result to closest integer Option “-qp”, range [ 0 ; 31 ] , default = 12 # - return block of quantization # indexes (integer values) Write/read to/from header with 8 bits def quant( self , transformBlock ): ... # Dequantization : Quantization and Dequantization # - multiply quantization indexes # of given block (integer) with QP Quantization step size: ∆ = 2 # quantization step size (float) 4 � u # - return reconstructed block � # of coefficients (floating point) Quantization (encoder): q = round def dequant( self , quantIndexes ): ∆ ... u ′ = ∆ · q Dequantization (decoder): Heiko Schwarz (Freie Universität Berlin) — Image and Video Coding
Exercise 4d: Integration and Testing (with transform coding of sample blocks) Goal: First real image codec Integration Encoder operation per block 1 Subtract middle gray value (128) Integrate padding, transform, quantization 2 Forward transform (exercise 4b) Check header: Image size, block size, QP 3 Quantization (exercise 4c) At end of block processing in decoder 4 Entropy coding (Exp-Golomb code) Add clipping to 8-bit range [ 0 ; 255 ] Testing and Evaluation Select at least 3 different test images Decoder operation per block Generate rate-PSNR curves by running codec 1 Entropy decding (Exp-Golomb code) with different QP values { 8 , 12 , 16 , 20 , 24 } 2 Dequantization (exercise 4c) measure rate and PSNR (using PSNR tool) 3 Inverse transform (exercise 4b) Repeat with different block sizes { 1 , 2 , 4 , 8 , 16 , 32 } 4 Add middle gray value (128) Compare curves to JPEG (see git repository) 5 Clip to 8-bit range [ 0 ; 255 ] (add) Heiko Schwarz (Freie Universität Berlin) — Image and Video Coding
Exercise 4e: Diagonal Scanning of Quantization Indexes Goal: Prepare improved entropy coding by adding suitable scan (similar to zig-zag scan) Scanning of Quantization Indexes Implement diagonal scan (as used in HEVC) shown in figure (scan used in HEVC) Implementation should work for all square block sizes Suggestion: Store scan pattern in array Initialize array at start of encoder/decoder depending on block size used Test Implementation Use the diagonal scan for entropy encoding and decoding (i.e., quantization indexes are en-/decoded in scan order) Coding efficiency should not change (same bitstream size) Heiko Schwarz (Freie Universität Berlin) — Image and Video Coding
Recommend
More recommend