Image Compression-JPEG
Lossless and Lossy Compression Lossless Lossy 144:1
JPEG ( Joint Photographic Experts Group) Formed in 1986 by ISO and CCITT (ITU-T) Became International Standard (IS) in 1991 Compression ratio 10 to 50; 0.5 to 2 bpp. At 1 bpp, one 256×256 image takes only 2 sec at 33.6 kbits/s Digital Compression and Coding of Continuous-Tone Still Images (grayscale or color) ISO/IEC IS (ITU-T T.81): Requirements and guidelines ISO/IEC IS (ITU-T T.83): Compliance testing ISO/IEC IS (ITU-T T.84): Extensions
Picture Formats Up to lines and pels/line 8 or 12 bits precision Color-space independent Up to 255 color components Each component can be subsampled Interleaving To save bits
JPEG (Encoder and Decoder)
Transform Allow the most efficient representation Energy concentration Removal or heavy quantization of some coefficients Allow perceptually weighted quantization Easy for entropy coding Discrete Cosine Transform (DCT) Widely used in JPEG, H.26x, MPEG
YCbCr Color Space Y ′ is the luma component and CB and CR are the blue-difference and red- difference chroma components. Humans can see considerably more fine detail in the brightness of an image (the Y component) than in the color of an image (the Cb and Cr components).
Color Space Luminance Eye Sensitivity
DCT
SHIFT Before computing the DCT of the subimage, its gray values are shifted from a positive range to one centered around zero. For an 8-bit image each pixel has 256 possible values: [0,255]. To center around zero it is necessary to subtract by half the number of possible values, or 128 Subtracting 128 from each pixel value yields pixel values on [ − 128,127]
2D Discrete Cosine Transform For 8*8 blocks Inverse DCT
DCT The DCT transforms 64 pixels to a linear combination of these 64 squares. Horizontally is u and vertically is v.
DCT Example I=imread('lena.bmp'); x=I(1:8, 1:8); imshow(x) J=dct2(x); imshow(log(abs(J)),[]),colormap(jet(64)), colorbar
DC and AC Coefficients The DC coefficient is rather large value of the top-left corner. The remaining 63 coefficients are called the AC coefficients. The DCT temporarily increases the bit-depth of the image, since the DCT coefficients of an 8- bit/component image take up to 11 or more bits
Quantization The human eye is good at seeing small differences in brightness over a relatively large area, but not so good at distinguishing the exact strength of a high frequency brightness variation. This allows one to greatly reduce the amount of information in the high frequency components. This is done by simply dividing each component in the frequency domain by a constant for that component, and then rounding to the nearest integer. This is the main lossy operation in the whole process. As a result of this, it is typically the case that many of the higher frequency components are rounded to zero, and many of the rest become small positive or negative numbers, which take many fewer bits to store. The advantage of the DCT is its tendency to aggregate most of the signal in one corner of the result.
Quantization The quantized DCT coefficients are computed with where G is the unquantized DCT coefficients; Q is the quantization matrix above; and B is the quantized DCT coefficients. The JPEG Still Picture Compression Standard, Summary by Gregory K. Wallace (ftp://ftp.uu.net/graphics/jpeg/wallace.ps.gz)
Quantization (cont.) 8×8 quantization table Q[u,v] High-freq coefficients can be quantized more Color components can be quantized more q-factor (in some implementation) A scale factor applied to a fixed Q For example, using − 415 (the DC coefficient) and rounding to the nearest integer
Entropy Coding It involves arranging the image components in a "zigzag" order employing run-length encoding (RLE) algorithm that groups similar frequencies together, inserting length coding zeros, and then using Huffman coding on what is left.
Entropy Coding If the i-th block is represented by Bi and positions within each block are represented by (p,q) where p = 0, 1,..., 7 and q = 0, 1,..., 7, then any coefficient in the DCT image can be represented as Bi(p,q). Thus, in the above scheme, the order of encoding pixels (for the i-th block) is Bi(0,0), Bi(0,1), Bi(1,0), Bi(2,0), Bi(1,1), Bi(0,2), Bi(0,3), Bi(1,2) and so on. This encoding mode is called baseline sequential encoding. Encodes similar-positioned coefficients of all blocks in one go, followed by the next positioned coefficients of all blocks, and so on.
Entropy Coding So, if the image is divided into N 8×8 blocks {B0,B1,B2,..., Bn-1}, then progressive encoding encodes Bi(0,0) for all blocks, i.e., for all i = 0, 1, 2,...,N-1. This is followed by encoding Bi(0,1) coefficient of all blocks, followed by Bi(1,0)-the coefficient of all blocks, then Bi(2,0)- th coefficient of all blocks, JPEG's other code words represent combinations of (a) the number of significant bits of a coefficient, including sign, and (b) the number of consecutive zero coefficients that precede it.
Lossy Compression Since the quantization stage always results in a loss of information, JPEG standard is always a lossy compression codec. (Information is lost both in quantizing and rounding of the floating-point numbers.)
JPEG Encoder Encoder Decoder
DC Coding DC Prediction Diff(n) = DC(n) – DC(n–1) Histograms of the DC coefficients from the 8×8 DCT of Lenna, showing the entropy reduction with differential coding
Entropy Entropy Uncertainty of a signal source X Bits needed to resolve uncertainty Probability : Entropy :
Huffman Coding
Decoding Taking the DCT coefficient matrix (after adding the difference of the DC coefficient back in) Using the quantization matrix Taking the inverse DCT (type-III DCT) results in an image with values (still shifted down by 128) Add 128 Average absolute error of about 5 values per pixels
Tradeoff Between Quality and Size Full quality (Q = 100) 83, :1 Average quality (Q = 50) 15,138 15:1 Lowest quality (Q = 1) 1, :1
JPEG 2OOO Image Coding System (JTC , ISO 15444) Goals Low bit-rate compression e.g., below 0.25 bpp for highly detailed gray-level images Lossless and lossy compression in a single bitstream Large images More than 64K by 64K Single decompression architecture Transmission in noisy environments Computer generated imagery Compound documents: bi-level and gray-scale
Applications Low bandwidth dissemination of imagery Medical imagery lossless/lossy compression Pre-press imagery Client/server applications (World Wide Web) Electronic photography Photo and art digital libraries Security Facsimile Laser print rendering Scanner and digital copier memory buffers
References JPEG – William B. Pennebaker, Joan L. Mitchell, JPEG: Still Image Data Compression Standard, Van Nostrand Reinhold, New York, NY, 1993
Any Questions?