90 likes | 265 Views
Digital Image Processing Lecture 21: Lossy Compression May 18, 2005. Prof. Charlene Tsai. JPEG Algorithm. Lossy compression trades some acceptable data loss for greater rate of compression. There are many available, but the most popular is the one developed by JPEG – transform coding.
E N D
Digital Image Processing Lecture 21: Lossy CompressionMay 18, 2005 Prof. Charlene Tsai
JPEG Algorithm • Lossy compression trades some acceptable data loss for greater rate of compression. • There are many available, but the most popular is the one developed by JPEG – transform coding. • Coding not done on pixel values, but on a transform.
Transform • Discrete Cosine Transform (DCT) • Applying to 8x8 blocks, the forward and inverse DCT are • DCT are real-valued, high information-packing capability, and separable.
Comparison with FFT • Given the following sequence 10 25 40 55 70 85 100 115 • If using FFT, the inverse of the first 4 FFT coefficients gives 49 41 56 57 71 70 85 90 • If using DCT, the result is 11 23 41 56 69 84 102 114
JPEG Compression • For each 8x8 image block, perform the compression • Subtracting 128 from each value • Apply DCT • Normalization by dividing by matrix Q (the lossy part) • Turning most of the elements zero • Change the matrix into a vector by reading the nonzero element in a zigzag fashion.
(con’d) • The first element (DC coefficient) of the vector is encoded as the difference between itself and the DC of previous block. • Keeps all values (except the very first one) small • Compressed using RLE • Other values (AC coefficients) are compressed using Huffman coding • Rate of compression is controlled by scaling Q => more scaling, more compression (see page 413~415 for an example)
Decompression • Inverse the operations: • Decode Huffman encoding and RLE • Put the vector back to 8x8 matrix • Multiply by Q • Inverse DCT • Shift back by 128
The Lossless Parts • Huffman Coding and RLE for AC and DC terms, respectively. • We’ll focus the discussion on the AC terms • Each nonzero value x is assigned a category k • The number of preceding 0s (run). • Values: 7 -1 10 0 2 1 0 0 2 4 0 1 0 -1 • Category: 1 4 2 1 2 3 1 1 • Run: 0 0 1 0 2 0 1 1
Huffman Code Table • Part of JPEG baseline standard • See page 417 and 418 for the code table, and the application.