CS 414 Multimedia Systems Design Lecture 8 JPEG

  • Slides: 40
Download presentation
CS 414 – Multimedia Systems Design Lecture 8 – JPEG Compression (Part 3) Klara

CS 414 – Multimedia Systems Design Lecture 8 – JPEG Compression (Part 3) Klara Nahrstedt Spring 2012 CS 414 - Spring 2012

Administrative n MP 1 is posted CS 414 - Spring 2012

Administrative n MP 1 is posted CS 414 - Spring 2012

Today Covered Topics n Hybrid Coding: ¨ JPEG n Coding Reading: Section 7. 5

Today Covered Topics n Hybrid Coding: ¨ JPEG n Coding Reading: Section 7. 5 out of “Media Coding and Content Processing”, Steinmetz & Nahrstedt, Prentice Hall 2002 CS 414 - Spring 2012

Ubiquitous use of digital images CS 414 - Spring 2012

Ubiquitous use of digital images CS 414 - Spring 2012

Image Compression and Formats RLE, Huffman, LZW (Lossless Coding) n GIF n JPEG /

Image Compression and Formats RLE, Huffman, LZW (Lossless Coding) n GIF n JPEG / JPEG-2000 (Hybrid Coding) n Original 60 KB 98% less 1 KB CS 414 - Spring 2012

JPEG (Joint Photographic Experts Group) n Requirements: ¨ Very good compression ratio and good

JPEG (Joint Photographic Experts Group) n Requirements: ¨ Very good compression ratio and good quality image ¨ Independent of image size ¨ Applicable to any image and pixel aspect ratio ¨ Applicable to any complexity (with any statistical characteristics) CS 414 - Spring 2012

JPEG Belong to Hybrid Coding Schemes Lossy Coding Lossless Coding CS 414 - Spring

JPEG Belong to Hybrid Coding Schemes Lossy Coding Lossless Coding CS 414 - Spring 2012 RLE, Huffman or Arithmetic Coding

JPEG Compression (Baseline) 8 x 8 blocks Source Image B Image Preparation G R

JPEG Compression (Baseline) 8 x 8 blocks Source Image B Image Preparation G R DCT-based encoding FDCT Quantizer Entropy Encoder Table Image Processing CS 414 - Spring 2012 Compressed image data

1. Image Preparation n The image preparation is NOT BASED on ¨ 9 -bit

1. Image Preparation n The image preparation is NOT BASED on ¨ 9 -bit YUV encoding ¨ Fixed number of lines and columns ¨ Mapping of encoded chrominance n Source image consists of components (Ci) and to each component we assign YUV, RGB or TIQ signals. CS 414 - Spring 2012

Division of Source Image into Planes CS 414 - Spring 2012

Division of Source Image into Planes CS 414 - Spring 2012

Components and their Resolutions CS 414 - Spring 2012

Components and their Resolutions CS 414 - Spring 2012

Color Transformation (optional) n Down-sample chrominance components ¨ compress without loss of quality (color

Color Transformation (optional) n Down-sample chrominance components ¨ compress without loss of quality (color space) ¨ e. g. , YUV 4: 2: 2 or 4: 1: 1 n Example: 640 x 480 RGB to YUV 4: 1: 1 ¨Y is 640 x 480 ¨ U is 160 x 120 ¨ V is 160 x 120 CS 414 - Spring 2012

Image Preparation (Pixel Allocation) Each pixel is presented by ‘p’ bits, value is in

Image Preparation (Pixel Allocation) Each pixel is presented by ‘p’ bits, value is in range of (0, 2 p-1) n All pixels of all components within the same image are coded with the same number of bits n Lossy modes use precision 8 or 12 bits per pixel n Lossless mode uses precision 2 up to 12 bits per pixel n CS 414 - Spring 2012

Image Preparation - Blocks Images are divided into data units, called blocks – definition

Image Preparation - Blocks Images are divided into data units, called blocks – definition comes from DCT transformation since DCT operates on blocks n Lossy mode – blocks of 8 x 8 pixels; lossless mode – data unit 1 pixel n CS 414 - Spring 2012

Data Unit Ordering n Non-interleaved: scan from left to right, top to bottom for

Data Unit Ordering n Non-interleaved: scan from left to right, top to bottom for each color component n Interleaved: compute one “unit” from each color component, then repeat ¨ full color pixels after each step of decoding ¨ but components may have different resolution CS 414 - Spring 2012

Example of Interleaved Ordering MCU: Minimum Coding Unit CS 414 - Spring 2012 [Wallace,

Example of Interleaved Ordering MCU: Minimum Coding Unit CS 414 - Spring 2012 [Wallace, 1991]

2. Image Processing n Shift values [0, 2 P - 1] to [-2 P-1,

2. Image Processing n Shift values [0, 2 P - 1] to [-2 P-1, 2 P-1 - 1] ¨ e. g. if (P=8), shift [0, 255] to [-127, 127] ¨ DCT requires range be centered around 0 n Values in 8 x 8 pixel blocks are spatial values and there are 64 samples values in each block CS 414 - Spring 2012

Forward DCT n Convert from spatial to frequency domain ¨ convert intensity function into

Forward DCT n Convert from spatial to frequency domain ¨ convert intensity function into weighted sum of periodic basis (cosine) functions ¨ identify bands of spectral information that can be thrown away without loss of quality n Intensity values in each color plane often change slowly CS 414 - Spring 2012

1 D Forward DCT Given a list of n intensity values I(x), where x

1 D Forward DCT Given a list of n intensity values I(x), where x = 0, …, n-1 n Compute the n DCT coefficients: n CS 414 - Spring 2012

Visualization of 1 D DCT Basic Functions F(0) F(1) F(2) F(3) F(4) CS 414

Visualization of 1 D DCT Basic Functions F(0) F(1) F(2) F(3) F(4) CS 414 - Spring 2012 F(5) F(6) F(7)

1 D Inverse DCT Given a list of n DCT coefficients F(u), where u

1 D Inverse DCT Given a list of n DCT coefficients F(u), where u = 0, …, n-1 n Compute the n intensity values: n CS 414 - Spring 2012

Extend DCT from 1 D to 2 D n Perform 1 D DCT on

Extend DCT from 1 D to 2 D n Perform 1 D DCT on each row of the block n Again for each column of 1 D coefficients ¨ alternatively, transpose the matrix and perform DCT on the rows Y X

Equations for 2 D DCT n Forward DCT: n Inverse DCT:

Equations for 2 D DCT n Forward DCT: n Inverse DCT:

Visualization of 2 D DCT Basis Functions. Increasing frequency CS 414 - Spring 2012

Visualization of 2 D DCT Basis Functions. Increasing frequency CS 414 - Spring 2012

Coefficient Differentiation n F(0, 0) ¨ includes the lowest frequency in both directions ¨

Coefficient Differentiation n F(0, 0) ¨ includes the lowest frequency in both directions ¨ is called DC coefficient ¨ Determines fundamental color of the block n F(0, 1) …. F(7, 7) ¨ are called AC coefficients ¨ Their frequency is non-zero in one or both directions CS 414 - Spring 2012

3. Quantization n n Throw out bits Consider example: 1011012 = 45 (6 bits)

3. Quantization n n Throw out bits Consider example: 1011012 = 45 (6 bits) We can truncate this string to 4 bits: 10112 = 11 ¨ We can truncate this string to 3 bits: 1012 = 5 (original value 40) or 1102 = 6 (original value 48) ¨ n n Uniform quantization is achieved by dividing DCT coefficients by N and round the result (e. g. , above we used N=4 or N=8) In JPEG – use quantization tables Fq(u, v) = F(u, v)/Quv ¨ Two quantization tables – one for luminance and one for two chrominance components ¨ CS 414 - Spring 2012

De facto Quantization Table Eye becomes less sensitive 16 11 10 16 24 40

De facto Quantization Table Eye becomes less sensitive 16 11 10 16 24 40 51 61 12 12 14 19 26 58 60 55 14 13 16 24 40 57 69 56 14 17 22 29 51 87 80 62 18 22 37 56 68 109 103 77 24 35 55 64 81 104 113 92 49 64 78 87 103 121 120 101 72 92 95 98 112 100 103 99 Eye becomes less sensitive CS 414 - Spring 2012

4. Entropy Encoding n Compress sequence of quantized DC and AC coefficients from quantization

4. Entropy Encoding n Compress sequence of quantized DC and AC coefficients from quantization step ¨ further n increase compression, without loss Separate DC from AC components ¨ DC components change slowly, thus will be encoded using difference encoding CS 414 - Spring 2012

DC Encoding n DC represents average intensity of a block ¨ encode n using

DC Encoding n DC represents average intensity of a block ¨ encode n using difference encoding scheme Because difference tends to be near zero, can use less bits in the encoding ¨ categorize difference into difference classes ¨ send the index of the difference class, followed by bits representing the difference CS 414 - Spring 2012

Difference Coding applied to DC Coefficients CS 414 - Spring 2012

Difference Coding applied to DC Coefficients CS 414 - Spring 2012

AC Encoding n Use zig-zag ordering of coefficients ¨ orders frequency components from low->high

AC Encoding n Use zig-zag ordering of coefficients ¨ orders frequency components from low->high ¨ produce maximal series of 0 s at the end ¨ Ordering helps to apply efficiently entropy encoding Apply Huffman coding n Apply RLE on AC zero values n CS 414 - Spring 2012

Huffman Encoding n Sequence of DC difference indices and values along with RLE of

Huffman Encoding n Sequence of DC difference indices and values along with RLE of AC coefficients n Apply Huffman encoding to sequence n Attach appropriate headers n Finally have the JPEG image! CS 414 - Spring 2012

Interchange Format of JPEG CS 414 - Spring 2012

Interchange Format of JPEG CS 414 - Spring 2012

Example - One Everyday Photo 2. 76 M CS 414 - Spring 2012

Example - One Everyday Photo 2. 76 M CS 414 - Spring 2012

Example - One Everyday Photo 600 K CS 414 - Spring 2012

Example - One Everyday Photo 600 K CS 414 - Spring 2012

Example - One Everyday Photo 350 K CS 414 - Spring 2012

Example - One Everyday Photo 350 K CS 414 - Spring 2012

Example - One Everyday Photo 240 K CS 414 - Spring 2012

Example - One Everyday Photo 240 K CS 414 - Spring 2012

Example - One Everyday Photo 144 K CS 414 - Spring 2012

Example - One Everyday Photo 144 K CS 414 - Spring 2012

Example - One Everyday Photo 88 K CS 414 - Spring 2012

Example - One Everyday Photo 88 K CS 414 - Spring 2012

Discussion n What types of image content would JPEG work best (worst) for? n

Discussion n What types of image content would JPEG work best (worst) for? n Is image compression solved? n What’s missing from JPEG? CS 414 - Spring 2012