VIEWS: 18 PAGES: 38 POSTED ON: 7/29/2012
JPEG-Still Image Compression Standard Introduction The JPEG Lossless Coding Algorithm Baseline JPEG Compression Progressive DCT-Based Mode Hierarchical Mode November 2010 Multimedia Computing Introduction • JPEG is the first image compression standard for continuous tone still images • Acronym for Joint Photographic Experts Group • Officially referred to as – ISO/IEC IS (International Standard) 10918-1: Digital Compression and Coding of Continuous-tone Still Images – ITU-T Recommendation T.81 November 2010 Multimedia Computing Introduction [contd..] • Goal of the standard is to support a variety of applications for compression of continuous-tone still images of most image sizes in any color space in order to achieve compression performance at or near the state-of-the-art with user-adjustable compression ratios and with very good to excellent reconstructed quality November 2010 Multimedia Computing Introduction [contd..] • JPEG defines four modes of operation 1. Sequential Lossless Mode: Compress the image in a single scan and the decoded image is an exact replica of the original image. 2. Sequential DCT-based Mode: Compress the image in a single scan using DCT-based lossy compression technique. As a result, the decoded image is not an exact replica, but an approximation of the original image. 3. Progressive DCT-based Mode: Compress the image in multiple scans and also decompress the image in multiple scans with each successive scan producing a better-quality image. 4. Hierarchical Mode: Compress the image at multiple resolutions for display on different devices. November 2010 Multimedia Computing Introduction [contd..] • Modes 2, 3 and 4 are lossy • Mode 1 uses predictive coding with no quantization, hence lossless • Sequential DCT-based JPEG algorithm – In it’s simplest form called baseline JPEG algorithm, which is based on Huffman coding for entropy encoding – The other form is based on arithmetic coding for entropy encoding November 2010 Multimedia Computing The JPEG Lossless Coding Algorithm • Based on the principle of predictive coding, a simple method for spatial redundancy reduction • The difference between the actual pixel value and the predicted value is called the differential or the prediction error value & is entropy encoded using a variable-length encoding technique • Differential Pulse Code Modulation (DPCM) ?? November 2010 Multimedia Computing The JPEG Lossless Coding Algorithm [contd..] • The value of the pixel in location X is predicted using one or more of 3-neighbors as shown in Fig-(a) • Then the prediction error / prediction residual is coded using Huffman coding / Arithmetic Coding Fig (a) : 3-pixel neighborhood for pixel X Fig (b) : Encoder Diagram for Lossless mode November 2010 Multimedia Computing The JPEG Lossless Coding Algorithm [contd..] • Eight possible options for Table-1 : Prediction Functions for Lossless JPEG predictions Option Prediction Type Of Prediction • Option-0 is available for only Function JPEG compression in 0 No Prediction Differential coding hierarchical mode 1 Xp=A 1-D horiz. Predict • Options 1-3 are 1-Dimensional 2 Xp=B 1-D Vert. Predict Predictors 3 Xp=C 1-D Diagonal Predict. • Options 4-7 are 2-Dimensional 4 Xp=A+B-C 2-D Prediction Predictors 5 Xp=A+½ (B-C) 2-D Prediction • The Chosen Predictor function is 6 Xp=B+½ (A-C) 2-D Prediction available at the header of the compressed file 7 Xp=½ (A+B) 2-D Prediction November 2010 Multimedia Computing The JPEG Lossless Coding Algorithm [contd..] • Precision of the source image can be from 2 to 16 bits • The very first pixel is calculated as follows – 2 P-Pt-1 • P - Precision of the Source image • Pt – Point Transform Parameter (default value =0) • For the pixels in the first row, except first pixel, use option-1 for prediction • The first pixel of second row to the last row are predicted using option-2 • Every other pixels are predicted using the chosen prediction function November 2010 Multimedia Computing The JPEG Lossless Coding Algorithm [contd..] • Prediction residuals are calculated for modulo 216 • The Prediction residuals are first represented using (CATEGORY, MAGNITUDE) pair – CATEGORY • Category of error Value • Represents number of bits needed to represent the error – MAGNITUDE – Variable length integer (VL1) to represent the error • Only the CATEGORY value in each pair is Huffman coded, not the other one November 2010 Multimedia Computing The JPEG Lossless Coding Algorithm [contd..] • The 2-step pair formation process is as follows 1. Huffman code CATEGORY 2. Append it to CATEGORY number of bits to represent MAGNITUDE 1. If MAGNITUDE is positive, Append As Such (hence starts with 1) 2. If MAGNITUDE is negative, Append 1’s complement November 2010 Multimedia Computing The JPEG Lossless Coding Algorithm [contd..] • For prediction residual 25 – The pair becomes (5,25) – Assuming the Huffman code for 5 is 011, the representation would be • 01111001 • –25 is represented as, – 01100110 Table 2: Categories of Prediction Error Values November 2010 Multimedia Computing The JPEG Lossless Coding Algorithm [contd..] • So, Why not using Huffman code Just for the complete range of prediction residuals? – Huffman table with 216 entries for all the 216 possible symbols of prediction residuals !!! November 2010 Multimedia Computing Baseline JPEG Compression • Defined for continuous tone images with 1 to 4 components – Grayscale image consists only one component – Only 8 bits allowed for each component • Good compression relies on exploiting the inter- component correlation between the R, G, B components • Image in R,G B components is converted into Luminance-Chrominance components – Chrominance Components are further subsampled November 2010 Multimedia Computing Baseline JPEG Compression [contd..] COLOR SPACE CONVERSIONS • Converting from RGB to YCBCR • CB & CR can result in negative. To bring it to positive & representable in 8 bits November 2010 Multimedia Computing Baseline JPEG Compression [contd..] COLOR SPACE CONVERSIONS • The inverse color transformation is • Baseline JPEG supports the subsampling of CB & CR according to 4:2:2 or 4:4:4 color formats – Choosing 4:2:2 would be the first lossy step in the baseline compression • The color space conversion is not applicable for Grayscale images November 2010 Multimedia Computing Baseline JPEG Compression [contd..] SOURCE IMAGE DATA ARRANGEMENT • Dimension of each component Y, Cb and Cr could be different, due to subsampling • Each component is divided into 8 x 8 non overlapping blocks • In non interleaved scan, each data blocks are coded from left to right & top to bottom • In Interleaved scan, Minimum coded Unit (MCU) consists data blocks from all the three components November 2010 Multimedia Computing Baseline JPEG Compression [contd..] SOURCE IMAGE DATA ARRANGEMENT (a) YCbCr 4:4:4, (b) YCbCr 4:2:2, (c) YCbCr 4:2:0. November 2010 Multimedia Computing Baseline JPEG Compression [contd..] BASELINE COMPRESSION ALGORITHM November 2010 Multimedia Computing Baseline JPEG Compression [contd..] BASELINE COMPRESSION ALGORITHM • Level shift each pixel in the 8 x 8 block & convert it to signed integer (subtract 128) • Transform each pixel in the block into frequency domain via forward discrete cosine transform (FDCT) • The FDCT for 8 x 8 block is defined by • For u = 0 7 & v = 07 and November 2010 Multimedia Computing Baseline JPEG Compression [contd..] CODING DCT COEFFICIENTS • Transformed 8 × 8 block now consists of 64 DCT coefficients – The first coefficient F(0, 0) is the DC component of the block • DC components is the sum of all the 64 pixels in the input scaled by 1/8 – Remaining 63 coefficients are AC components ACu,v = F(u, v) of the block DC and AC components of the transformed block. Transformation is done… next step in coding? QUANTIZATION November 2010 Multimedia Computing Baseline JPEG Compression [contd..] CODING DCT COEFFICIENTS • Each of the 64 coefficients are uniformly quantized • Quantization Matrix gives the 64 quantization step-size parameters for uniform quantization of the 64 DCT coefficients – Each element in the quantization matrix is an integer between 1 and 255. – Each DCT coefficient F(u, v) is divided by the corresponding quantizer step-size parameter Q(u, v) in the quantization matrix and rounded to the nearest integer as November 2010 Multimedia Computing Baseline JPEG Compression [contd..] CODING DCT COEFFICIENTS Luminance Quantization Matrix Chrominance Quantization Matrix November 2010 Multimedia Computing Baseline JPEG Compression [contd..] CODING DCT COEFFICIENTS • Quality of the reconstructed image and the achieved compression can be controlled by a user by selecting a quality factor Q_JPEG – Q_JPEG ranges between 1 to 100 – When Q_JPEG is used, the entries in tables in previous slide is scaled by the factor alpha (α), defined as – Q_JPEG is 100 for best reproduction Quantization is done… Proceeding to coding the quantized values… November 2010 Multimedia Computing Baseline JPEG Compression [contd..] CODING DCT COEFFICIENTS • Quantized DC coefficient is encoded by differential encoding – DC coefficient DCi of the current block is subtracted by the DC coefficient DCi−1 of the previous block – The difference DIFF = DCi − DCi−1 is encoded • Encoding AC Components – Only the nonzero coefficients are encoded by an efficient manner such that the runs of zeros preceding a nonzero value are embedded into the encoding. – Irregular ordering of the AC coefficients is called zig-zag ordering November 2010 Multimedia Computing Baseline JPEG Compression [contd..] CODING DCT COEFFICIENTS (a) Zig-zag ordering of AC coefficients (b) differential coding of DC November 2010 Multimedia Computing Baseline JPEG Compression [contd..] CODING DCT COEFFICIENTS • The zig-zag sequence of AC component broken into a no. of runs of zeros ending in a nonzero coefficient • For 8-bit images in baseline JPEG, the DCT coefficients fall in the range [−1023, +1023] – Differential values of DC fall in the range [−2047, +2047] November 2010 Multimedia Computing Baseline JPEG Compression [contd..] CODING DCT COEFFICIENTS • This sequence of AC coefficients is mapped into an intermediate sequence of a combination of two symbols, symbol1, symbol2 – symbol1 is represented by a pair (RUNLENGTH, CATEGORY) • RUNLENGTH is the number of consecutive zeros preceding the nonzero AC coefficient being encoded • CATEGORY is the number of bits to represent the VLI code of this nonzero AC coefficient – symbol2 is a single piece of information designated (AMPLITUDE) that is encoded by the VLI code of the nonzero AC coefficient. November 2010 Multimedia Computing Baseline JPEG Compression [contd..] CODING DCT COEFFICIENTS • Assume the zigzag ordering results in the sequence as follows −6 6 −5 0 2 0 −1 0 0 0 0 0 −1 0 0 −1 1 0 0 000000000000000000000000 00000000000000000000 • This can be represented as (0, 3)(−6), (0, 3)(6), (0, 3)(−5), (1, 2)(2), (1, 1)(−1), (5, 1)(−1), (2, 1)(−1), (0, 1)(1), (0,0). November 2010 Multimedia Computing Baseline JPEG Compression [contd..] CODING DCT COEFFICIENTS • Two special symbols in encoding the zig-zag sequence of AC coefficients – (0,0) referred to as EOB (end-of-block), to indicate that the remaining elements in the zig-zag block are zeros – (15, 0)referred to as ZRL (zero-run-length) to indicate a run of 16 zeros • Maximum length of a run of zeros allowed in baseline JPEG is 16 – Runs of more than 16 zeros should be broken into the number of runs of zeros of length 16. • Example : 57 zeros before a nonzero coefficient,−29. – Represented by (15, 0) (15, 0) (15, 0), (9, 5)(−29) November 2010 Multimedia Computing Baseline JPEG Compression [contd..] EXAMPLE A Sample 8 × 8 Data Block After Level Shifting November 2010 Multimedia Computing Baseline JPEG Compression [contd..] EXAMPLE DCT Coefficients of the Above 8 × 8 Block Results of DCT Coefficients Quantized by Luminance Quantization Matrix November 2010 Multimedia Computing Baseline JPEG Compression [contd..] EXAMPLE The Zig-Zag Sequence to be coded is −6 6 −5 0 2 0 −1 0 0 0 0 0 −1 0 0 −1 1 0 0 0 0 000000000000000000000000 000000000000000000 And the code is (0, 3)(−6), (0, 3)(6), (0, 3)(−5), (1, 2)(2), (1, 1)(−1), (5, 1)(−1), (2, 1)(−1), (0, 1)(1), (0,0). November 2010 Multimedia Computing Baseline JPEG Compression [contd..] EXAMPLE (a) Original Pepper image (b) Compressed with baseline JPEG using quality factor 75 (1.57 bit/pixel) (c) Compressed with baseline JPEG using quality factor 10 (0.24 bit/pixel) (d) Compressed with the new JPEG2000 standard using the same bit rate (0.24 bit/pixel). November 2010 Multimedia Computing Progressive DCT-Based Mode • The image is coded sequentially in multiple scan – Need to wait till the decoding is over to view the image in sequential mode • Transmit a coarser version of the image in the first scan and then progressively improve the reconstructed quality at the receiver by transmitting more compressed bits in successive scans – Complete the computation of DCT coefficients before the start of entropy coding – Perform selective encoding of the DCT coefficients & transmit – Two methods • spectral selection and successive approximation November 2010 Multimedia Computing Progressive DCT-Based Mode [contd..] PROGRESSIVE CODING SUCESSIVE APPROXIMATION • Encode sets of DCT coefficients • Start encoding with certain number starting from lower frequencies and of most significant bits (say N1) of moving progressively to higher all the DCT coefficients of all the frequencies. blocks and transmit in the first scan. – For example • Encode all the DC coefficients of • In the second scan, the following N2 all the 8 × 8 DCT blocks in the first most significant bits are encoded scan and transmitted and so on. • Encode and transmit the first three AC coefficients of the zig-zag • The scans continue until the least sequence of all the DCT blocks in significant bit of all the coefficients the second scan • Transmit the next 3 AC coefficients is encoded. Usually the successive in the third scan, and so on approximation offers better • The last three AC coefficients can reconstructed quality in the earlier be transmitted in the 21st scan scans compared to the spectral • Number of coefficients in each scan could be different and user selection method. selectable. November 2010 Multimedia Computing Progressive DCT-Based Mode [contd..] Progressive encoding: (a) spectral selection (b) successive approximation. November 2010 Multimedia Computing Hierarchical Mode • Progressive coding with increasing spatial resolution in a number of stages • Original image is filtered and down-sampled by required multiples of two for the target resolution and the lower-resolution image is encoded using any of the other three JPEG modes • The compressed lower-resolution image is then decoded and interpolated for upsampling by the same interpolation method that will be used at the decoder • Interpolated image is then subtracted from the next-higher-resolution image. The difference is then encoded by one of the other three JPEG Hierarchical multiresolution encoding. modes (lossless or lossy). This procedure of the hierarchical encoding process is continued until it encodes all the resolutions. November 2010 Multimedia Computing