190 likes | 385 Views
Data Compression (3). Hai Tao. JPEG Compression. JPEG is the image compression standard developed by the Joint Photographic Experts Group JPEG was designed for natural image compression It convert the original image into YIQ space and compress each channel as a separate gray image
E N D
Data Compression (3) Hai Tao
JPEG Compression • JPEG is the image compression standard developed by the Joint Photographic Experts Group • JPEG was designed for natural image compression • It convert the original image into YIQ space and compress each channel as a separate gray image • 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
Quality factor Quality factor = 20 Original Quality factor = 75 Quality factor = 5
JPEG Compression – Algorithm Overview • An input image is divided into 8x8 blocks. Each block is encoded based on DCT transform • DCT coefficients are quantized according to a quatization matrix • Entropy coding is used to encode positions and the magnitudes of the coefficients
Color space conversion • 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
JPEG – 8x8 DCT Transformation • After DCT compression, only a few DCT coefficients have large values in each 8x8 block • These coefficients are floating-point numbers
Quantization of the DCT Coefficients • Each coefficients are converted into an integer number using quatization • 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 ?
3 5 7 9 11 13 15 17 5 7 9 11 13 15 17 19 7 9 11 13 15 17 19 21 9 11 13 15 17 19 21 23 11 13 15 17 19 21 23 25 13 15 17 19 21 23 25 27 15 17 19 21 23 25 27 29 17 19 21 23 25 27 29 31 JPEG Quantization Matrix • The low frequency coefficients (upper-left corner) have smaller quantization steps, therefore more accurately encoded
90 92 30 3 0 0 -9 -7 -1 -7 0 0 3 0 0 -1 0 0 0 0 0 2 0 0 -39 -7 -35 -58 -8 -56 12 1 9 17 11 1 -2 0 0 2 0 0 4 0 0 2 0 0 -12 -84 -84 62 6 54 1 0 0 -18 -1 -13 3 0 0 4 0 0 -5 0 0 5 0 0 -5 -52 -45 -36 -3 -33 -10 0 0 14 0 0 -10 0 0 4 0 0 -2 0 0 0 0 0 -86 -7 -77 -40 -3 -39 49 3 45 -7 0 0 17 0 0 -6 0 0 -2 0 0 5 0 0 -52 -4 -62 65 60 4 -12 0 0 -2 0 0 3 0 0 -8 0 0 -2 0 0 0 0 0 -17 -15 -1 14 0 0 -36 -1 -19 17 0 0 -11 0 0 3 0 0 3 0 0 -1 0 0 -3 -54 -51 32 19 1 -9 0 0 -9 0 0 22 0 0 0 0 0 1 0 0 3 0 0 JPEG Quantization Using the Quantization Matrix After quantization Before quantization After reconstruction
30 0 -1 0 0 0 0 0 -7 -8 1 1 0 0 0 0 -12 6 0 -1 0 0 0 0 -5 -3 0 0 0 0 0 0 -7 -3 3 0 0 0 0 0 -4 4 0 0 0 0 0 0 -1 0 -1 0 0 0 0 0 -3 1 0 0 0 0 0 0 Encoding • We need to compress the quantized coefficients • Lossless methods are used to • Encode the position of non-zero coefficients • Encode the magnitudes of these coefficients
Encoding • 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
30 0 -1 0 0 0 0 0 -7 -8 1 1 0 0 0 0 -12 6 0 -1 0 0 0 0 -5 -3 0 0 0 0 0 0 -7 -3 3 0 0 0 0 0 -4 4 0 0 0 0 0 0 -1 0 -1 0 0 0 0 0 -3 1 0 0 0 0 0 0 Example • 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) • These pairs are encoded using a entropy coding method
JPEG Bitstream • Terminology • Frame – image • Block – 8x8 image block • Segment – a group of blocks • 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)
JPEG Bitstream • Scan header • Number of components in scan component ID (for each component) Huffman table for each component (for each component) • Misc. (can occur between headers) • Quantization tables Huffman Tables Arithmetic Coding Tables Comments Application Data
Various JPEG modes • Baseline/Sequential • Lossless mode • 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
Decoding • Decoding is the inverse process of the encoding • Recover the quantized coefficient matrix • Recover the coefficient matrix • IDCT • JPEG is lossy because of the quatization process
Evaluation • 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
Evaluation • The rate distortion curve