Department of Computer Engineering University of California at Santa Cruz Data Compression (3) Hai Tao
Department of Computer Engineering University of California at Santa Cruz JPEG Compression n JPEG is the image compression standard developed by the Joint Photographic Experts Group n JPEG was designed for natural image compression n It convert the original image into YIQ space and compress each channel as a separate gray image n The compression ratio and the quality of the decoded images is controlled by quality factor (1-100) Quality factor > 35 - no big difference Quality factor < 10 – significant difference
Department of Computer Engineering University of California at Santa Cruz Quality factor n Original Quality factor = 20 Quality factor = 75 Quality factor = 5
Department of Computer Engineering University of California at Santa Cruz JPEG Compression – Algorithm Overview n An input image is divided into 8x8 blocks. Each block is encoded based on DCT transform n DCT coefficients are quantized according to a quatization matrix n Entropy coding is used to encode positions and the magnitudes of the coefficients
Department of Computer Engineering University of California at Santa Cruz Color space conversion n Human visual system has less resolution in color than in intensity. As a result, the original color images are converted into intensity and color channels. One such transformation is RGB->YIQ
Department of Computer Engineering University of California at Santa Cruz JPEG – 8x8 DCT Transformation n After DCT compression, only a few DCT coefficients have large values in each 8x8 block n These coefficients are floating-point numbers
Department of Computer Engineering University of California at Santa Cruz Quantization of the DCT Coefficients n Each coefficients are converted into an integer number using quatization n The choices of quatization steps Large quantization step - Large rounding errors, smaller quantized values Small quatization step – Small rounding errors, large quantized coefficients The same quatization step for all coefficients ? – Human visual system is more sensitive to relative low frequency changes in images, which implies that for high frequency coefficients, larger quantization steps can be used without causing noticeable image distortion What does all this means ?
Department of Computer Engineering University of California at Santa Cruz JPEG Quantization Matrix n The low frequency coefficients (upper-left corner) have smaller quantization steps, therefore more accurately encoded
Department of Computer Engineering University of California at Santa Cruz JPEG Quantization Using the Quantization Matrix Before quantization After quantization After reconstruction
Department of Computer Engineering University of California at Santa Cruz Encoding n We need to compress the quantized coefficients n Lossless methods are used to Encode the position of non-zero coefficients Encode the magnitudes of these coefficients
Department of Computer Engineering University of California at Santa Cruz Encoding n Zig-Zag encoding of coefficient positions Non-zero coefficients and the number of 0’s in front of them are encoded along the zig-zag path
Department of Computer Engineering University of California at Santa Cruz Example n The following quantized coefficient matrix is represented as (30,0), (-7,1), (-12, 0), (-8, 0), (-1, 0), (1,1),(6,0),(-5,0),(-7,0),(-3,0), (1,1), (-1,3),(-3,1),(-4,0), (-1,0), (4,0), (3,0),(-3,11),(1,0), (-1,0),(end) n These pairs are encoded using a entropy coding method
Department of Computer Engineering University of California at Santa Cruz JPEG bit stream n
Department of Computer Engineering University of California at Santa Cruz JPEG Bitstream n Terminology Frame – image Block – 8x8 image block Segment – a group of blocks n Frame header Sample precision (width, height) of image number of components unique ID (for each component) horizontal/vertical sampling factors (for each component) quantization table to use (for each component)
Department of Computer Engineering University of California at Santa Cruz JPEG Bitstream n Scan header Number of components in scan component ID (for each component) Huffman table for each component (for each component) n Misc. (can occur between headers) Quantization tables Huffman Tables Arithmetic Coding Tables Comments Application Data
Department of Computer Engineering University of California at Santa Cruz Various JPEG modes n Baseline/Sequential n Lossless mode n Progressive mode Display low quality image first, and then transmit and display more details Method 1: Send DC components first, then a few low frequency components, and then more components Method 2: Send significant bits first, then more less significant bits
Department of Computer Engineering University of California at Santa Cruz Decoding n Decoding is the inverse process of the encoding Recover the quantized coefficient matrix Recover the coefficient matrix IDCT n JPEG is lossy because of the quatization process
Department of Computer Engineering University of California at Santa Cruz Evaluation n To evaluate an image compression algorithm, there are two criteria Subjective - The visual quality vs. bit rate (subjective) Objective - The rate distortion curve (Peak SNR vs. bit rate) The difference image when the quality factor is 3
Department of Computer Engineering University of California at Santa Cruz Evaluation n The rate distortion curve