Introduction to JPEG Alireza Shafaei 79136107 Fall 2005















- Slides: 15
Introduction to JPEG Alireza Shafaei (79136107) Fall 2005
Bitmap Images n n RGB Color Model (Red, Green & Blue) 3 bytes of Information for each Pixel: q n Memory space of a 640 × 480 24 -bit RGB color image: q q n 1 byte for Red, 1 byte for Green & 1 byte for Blue 640 × 480 = 307, 200 pixels 307, 200 × 3 = 921, 600 bytes = 900 kilobytes Image Compression Methods (like JPEG)
What is JPEG? “Joint Photographic Expert Group”, A joint effort by the CCITT and the ISO. (1991) An Image Compression Method for continuoustone still images, both grayscale and color. Facts on Human Visual System used in JPEG: n n n 1. 2. The eye seems to be more sensitive at the luminance of a colour than at the nuance of that colour. (Y & Cb. Cr) The eye is much more sensitive to lower spatial frequencies than to higher frequencies
JPEG Encoding Steps JPEG Baseline Sequential Mode: n 1. 2. 3. 4. 5. 6. Color Space Transformation & Sampling DCT Quantization Zig-Zag Scan DPCM & RLE Entropy Coding
Color Space Transformation n n RGB to YCb. Cr Y is Luminance (Brightness). RGB Y Cb. Cr is the Chrominance. + Sampling: RGB Cb Cr (Down Sampling)
RGB to YCb. Cr 8 RGB 8 Y Y 8 Cb 8 Cr + 8 RGB 8 8 4 x 64 x 3 byte 8 Y Y 8 8 4 x 64 x 1 byte 8 2 x 64 x 1 byte Y = 0. 299 R + 0. 587 G + 0. 114 B n First the image is divided into 8 x 8 blocks. Cb = - 0. 169 R - 0. 331 G + 0. 500 B Cr = 0. 500 R - 0. 419 G - 0. 081 B
Discrete Cosine Transform (DCT) 8 sxy 8 DCT 8 Coefficients 8
DCT (cont’d) n Why we apply DCT? q n Why not FFT? q n DCT is like FFT, but can approximate linear signals well with few [real] coefficients. DCT is slow q n To move from Spatial Domain to Frequency Domain. 1024 multiplications and 896 additions. JPEG 2000: Wavelet Transforms.
Quantization n n DCT Coefficients are 12 bits per sample. Why Quantization? q n n n To reduce number of bits per sample. F'[u, v] = round ( F[u, v] / Q[u, v] ) Two Quantization Tables are used in JPEG Header File (QY & QCb. Cr). Quantization error is the main source of the Lossy Compression.
Zig Zag Scan n n 8 x 8 Blocks to a 1 x 64 Vector. Why Zig Zag Scan? q To sort 8 x 8 DCT coefficients based on the spatial frequencies (low frequency coefficients in top of vector). 1 x 64 Vector: DC Component (No Frequency) 0 1 2 . . . 63 Highest Frequency
DPCM & RLE DPCM on DC Component 1. q q Differential Pulse Code Modulation. DC component is large and varied, but often close to previous value. RLE on AC Components 2. q q q Zero Run Length Encoding. 1 x 64 vector has lots of zeros in it. 57, 45, 0, 0, 23, 0, -30, -16, 0, 0, 1, 0, 0 , 0 , only 0, . . , 0 RLC: (0, 57); (0, 45); (4, 23); (1, -30); (0, -16); (2, 1); EOB = (0, 0)
Entropy Coding n n n Entropy Coding is a form of compression that relies on developing "code" words in a library for the input values or "symbols". Huffman Coding in JPEG. 4 Huffman Tables are stored in JPEG Header File: q q 2 tables for DC Component (Y & Cb. Cr) 2 tables for AC Components (Y & Cb. Cr)
JPEG Encoding Diagram
JPEG Decoding Inverse of Encoding. Steps: n n 1. 2. 3. 4. 5. 6. Decode Huffman Bit Stream Decode DC Component (DPCM) and AC Components (RLE) Unpack Anti-Zig. Zag Multiply by Quantization Apply Inverse DCT YCb. Cr to RGB
JPEG Decoding (cont’d) n Inverse DCT: n YCb. Cr to RGB: