Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks...

23
Image (and Video) Coding and Processing Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her sl
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    221
  • download

    0

Transcript of Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks...

Page 1: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Image (and Video) Coding and Image (and Video) Coding and ProcessingProcessing

Lecture: DCT Compression and JPEGLecture: DCT Compression and JPEG

Wade Trappe

Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Page 2: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Transform CodingTransform Coding

Page 3: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Lecture OverviewLecture Overview

We will talk first about the structure of transform coding– Zonal vs. Threshold Coding

– Block Size Issues

– Why should we Zig-Zag?

JPEG– The Steps in the Process

– Quantization

– Subsampling of chrominance

– Lossless part of JPEG

Page 4: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Transform CodingTransform Coding Use transform to pack energy to only a few coeff.

How many bits to be allocated for each coeff.?– More bits for coeff. with high variance k

2 to keep total MSE small– Also determined by perceptual importance

From Jain’s Fig.11.15

Page 5: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Zonal Coding and Threshold CodingZonal Coding and Threshold Coding

Zonal coding– Only transmit a small predetermined zone of transformed coeff.

Threshold coding– Transmit coeff. that are above certain thresholds

Compare– Threshold coding is inherently adaptive

introduce smaller distortion for the same # of coded coeff.

– Threshold coding needs overhead in specifying index of coded coeff. run-length coding helps to reduce overhead

Page 6: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Determining Block SizeDetermining Block Size Why block based?

– High transform computation complexity for large block

O( m log m m ) per blockin tranf. for (MN/m2) blocks

complexity in bit allocation

– Block transform captures local info. better than global transform

Rate & complexity vs. block size

– Commonly used block size ~ 8x8

From Jain’s Fig.11.16

complexity

Page 7: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Block-based Transform CodingBlock-based Transform Coding Encoder

– Step-1 Divide an image into m x m blocks and perfrom transform

– Step-2 Determine bit-allocation for coefficients

– Step-3 Design quantizer and quantize coefficients (lossy!)

– Step-4 Encode quantized coefficients

Decoder

From Jain’s Fig.11.17

Page 8: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

How to Encode Quantized Coeff. in Each How to Encode Quantized Coeff. in Each BlockBlock

Basic tools– Entropy coding (Huffman, etc.) and run-length coding

– Predictive coding ~ esp. for DC

Ordering– zig-zag scan for block-DCT to better achieve run-length coding gain

Horizontal frequency

Vertical frequency

DCAC01

AC07

AC70

AC77

low-frequency coefficients, then high frequency coefficients

Page 9: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Summary: List of Compression ToolsSummary: List of Compression Tools

Lossless encoding tools– Entropy coding: Huffman, Lemple-Ziv, and others (Arithmetic coding)

– Run-length coding

Lossy tools for reducing redundancy– Quantization: scalar quantizer vs. vector quantizer

– Truncations: discard unimportant parts of data

Facilitating compression via Prediction– Encode prediction parameters and residues with less bits

Facilitating compression via Transforms– Transform into a domain with improved energy compaction

Page 10: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Put Basic Tools Together: Put Basic Tools Together:

JPEG Image Compression StandardJPEG Image Compression Standard

Page 11: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

JPEG Compression Standard (early JPEG Compression Standard (early 1990s)1990s)

JPEG - Joint Photographic Experts Group– Compression standard of generic continuous-tone still image– Became an international standard in 1992

Allow for lossy and lossless encoding of still images– Part-1 DCT-based lossy compression

average compression ratio 15:1

– Part-2 Predictive-based lossless compression

Sequential, Progressive, Hierarchical modes– Sequential ~ encoded in a single left-to-right, top-to-bottom scan

– Progressive ~ encoded in multiple scans to first produce a quick, rough decoded image when the transmission time is long

– Hierarchical ~ encoded at multiple resolution to allow accessing low resolution without full decompression

Page 12: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Baseline JPEG AlgorithmBaseline JPEG Algorithm

“Baseline”– Simple, lossy compression

Subset of other DCT-based modes of JPEG standard

A few basics– 8x8 block-DCT based coding

– Shift to zero-mean by subtracting 128 [-128, 127] Allows using signed integer to represent both DC and AC

coeff.

– Color (YCbCr / YUV) and downsample Color components can have lower

spatial resolution than luminance

– Interleaving color components

B

G

R

C

C

Y

r

b

100.0515.0615.0

436.0289.0147.0

114.0587.0299.0

(Based on Wang’s video book Chapt.1)

Page 13: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Block Diagram of JPEG BaselineBlock Diagram of JPEG BaselineF

rom

Wal

lace

’s J

PE

G tu

tori

al (

1993

)

Page 14: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

475 x 330 x 3 = 157 KB luminance

Fro

m L

iu’s

EE

330

(Pri

ncet

on)

Page 15: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Y U V (Y Cb Cr) ComponentsY U V (Y Cb Cr) Components

Assign more bits to Y, less bits to Cb and Cr

Fro

m L

iu’s

EE

330

(Pri

ncet

on)

Page 16: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Lossless Coding Part in JPEGLossless Coding Part in JPEG

Differentially encode DC

– (lossy part: DC differences are then quantized.)

AC coefficients in one block

– Zig-zag scan after quantization for better run-length save bits in coding consecutive zeros

– Represent each AC run-length using entropy coding use shorter codes for more likely AC run-length

symbols

Page 17: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Lossy Part in JPEGLossy Part in JPEG

Quantization (adaptive bit allocation)– Different quantization step size for different coeff. bands

– Use same quantization matrix for all blocks in one image

– Choose quantization matrix to best suit the image

– Different quantization matrices for luminance and color components

Default quantization table– “Generic” over a variety of images

Quality factor “Q”– Scale the quantization table

– Medium quality Q = 50% ~ no scaling

– High quality Q = 100% ~ unit quantization step size

– Poor quality ~ small Q, larger quantization step visible artifacts like ringing and blockiness

Page 18: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

How Quantization is PerformedHow Quantization is Performed

Suppose you have an 8x8 DCT image X(u,v)

The quantizer output is:

I(u,v)=Round(X(u,v)/Q(u,v))

This rounds to the nearest integer

Here, Q(u,v) is a quantization table.

The default luminance table for JPEG is presented on the right

What to note:– Smaller Q(u,v) means a smaller

step size and hence more resolution

– Vice-versa

– Q(u,v) may be scaled by a quality factor

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

Page 19: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Uncompressed (100KB)

JPEG 75% (18KB)

JPEG 50% (12KB)

JPEG 30% (9KB)

JPEG 10% (5KB)

Page 20: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

JPEG Compression (Q=75% & 30%)JPEG Compression (Q=75% & 30%)

45 KB 22 KBFro

m L

iu’s

EE

330

(Pri

ncet

on)

Page 21: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Y Cb Cr After JPEG (Q=30%)Y Cb Cr After JPEG (Q=30%)

Fro

m L

iu’s

EE

330

(Pri

ncet

on)

JPEG Cb JPEG Cr

Page 22: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Lossless Coding Part in JPEG: DetailsLossless Coding Part in JPEG: Details Differentially encode DC

– ( SIZE, AMPLITUDE ), with amplitude range in [-2048, 2047]

AC coefficients in one block

– Zig-zag scan for better run-length

– Represent each AC with a pair of symbols

Symbol-1: ( RUNLENGTH, SIZE ) Huffman coded

Symbol-2: AMPLITUDE Variable length coded

RUNLENGTH [0,15] # of consecutive zero-valued AC coefficientspreceding the nonzero AC coefficient [0,15]

SIZE [0 to 10 in unit of bits] # of bits used to encode AMPLITUDE

AMPLITUDE in range of [-1023, 1024]

Page 23: Image (and Video) Coding and Processing Lecture: DCT Compression and JPEG Wade Trappe Again: Thanks to Min Wu for allowing me to borrow many of her slides.

Table is from slides at Gonzalez/ Woods DIP book website (Chapter 8)