image compression: coding and decoding

28
EE4328, Section 005 Introduction to Digital Image Processing Image Compression Zhou Wang Dept. of Electrical Engineering The Univ. of Texas at Arlington Fall 2006

Upload: flynn

Post on 13-Feb-2016

57 views

Category:

Documents


0 download

DESCRIPTION

EE4328, Section 005 Introduction to Digital Image Processing Image Compression Zhou Wang Dept. of Electrical Engineering The Univ. of Texas at Arlington Fall 2006. Image Compression: Coding and Decoding. original image 262144 Bytes. From [Gonzalez & Woods]. From [Gonzalez & Woods]. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Image Compression: Coding and Decoding

EE4328, Section 005 Introduction to Digital Image

Processing

Image Compression

Zhou Wang

Dept. of Electrical EngineeringThe Univ. of Texas at Arlington

Fall 2006

Page 2: Image Compression: Coding and Decoding

Image Compression: Coding and Decoding

compressed bitstream

00111000001001101…

(2428 Bytes)

imageencoder

imagedecoder

original image

262144 Bytes

compression ratio (CR) = 108:1

From [Gonzalez &

Woods]

From [Gonzalez &

Woods]

Page 3: Image Compression: Coding and Decoding

Some General Concepts

• How Can an Image be Compressed, AT ALL!?– If images are random matrices, better not to try any

compression– Image pixels are highly correlated redundant information

• Information, Uncertainty and Redundancy– Information is uncertainty (to be) resolved– Redundancy is repetition of the information we have– Compression is about removing redundancy because

• Entropy and Entropy Coding– Entropy is a statistical measure of uncertainty, or a

measure of the amount of information to be resolved– Entropy coding: approaching the entropy (no-redundancy)

limit

Page 4: Image Compression: Coding and Decoding

• Bit Rate and Compression Ratio– Bit rate: bits/pixel, sometimes written as bpp– Compression ratio (CR):

• Binary, Gray-Scale, Color Image Compression– Original binary image: 1 bit/pixel– Original gray-scale image: typically 8bits/pixel– Original Color image: typically 24bits/pixel

• Lossless, Nearly lossless and Lossy Compression– Lossless: original image can be exactly reconstructed– Nearly lossless: reconstructed image nearly (visually) lossless– Lossy: reconstructed image with loss of quality (but higher

CR)

More Concepts

number of bits to represent the original image

number of bits in compressed bit streamCR =

Page 5: Image Compression: Coding and Decoding

Binary Image Compression

Page 6: Image Compression: Coding and Decoding

Run Length Coding

row m

what'sstored: '1' 7 5 8 3 1

row m

what's stored: '1'1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

• Run Length– The length of consecutively identical symbols

• Run length Coding Example

• When Does it Work?– Images containing many runs of 1’s and 0’s

• When Does it Not Work?

Page 7: Image Compression: Coding and Decoding

Run Length Coding

CCITT test image No. 1Size: 172823761 bit/pixel (bpp)

original: 513216 bytes

compressed: 37588 bytes

CR = 13.65

Page 8: Image Compression: Coding and Decoding

Run Length Coding

• Decoding Example

Row 1: “0”, 16Row 2: “0”, 16Row 3: “0”, 7, 2, 7Row 4: “0”, 4, 8, 4Row 5: “0”, 3, 2, 6, 3, 2Row 6: “0”, 2, 2, 8, 2, 2Row 7: “0”, 2, 1, 10, 1, 2Row 8: “1”, 3, 10, 3Row 9: “1”, 3, 10, 3Row 10: “0”, 2, 1, 10, 1, 2Row 11: “0”, 2, 2, 8, 2, 2Row 12: “0”, 3, 2, 6, 3, 2Row 13: “0”, 4, 8, 4Row 14: “0”, 7, 2, 7Row 15: “0”, 16Row 16: “0”, 16

A binary image is encoded using run length code row by row, with “0” represents white, and “1” represents black. The code is given by

Decode the imagedecode

Page 9: Image Compression: Coding and Decoding

Run Length Coding

• Decoding Example

A binary image is encoded using run length code row by row, with “0” represents white, and “1” represents black. The code is given by

decode

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

123456

11

12

13

14

15

16

789

123456789

1 2 3 4 5 6 7 8 9 11 12 13 14 15 16

11

12

13

14

15

16

10

10 10

Row 1: “0”, 16Row 2: “0”, 16Row 3: “0”, 7, 2, 7Row 4: “0”, 4, 8, 4Row 5: “0”, 3, 2, 6, 3, 2Row 6: “0”, 2, 2, 8, 2, 2Row 7: “0”, 2, 1, 10, 1, 2Row 8: “1”, 3, 10, 3Row 9: “1”, 3, 10, 3Row 10: “0”, 2, 1, 10, 1, 2Row 11: “0”, 2, 2, 8, 2, 2Row 12: “0”, 3, 2, 6, 3, 2Row 13: “0”, 4, 8, 4Row 14: “0”, 7, 2, 7Row 15: “0”, 16Row 16: “0”, 16

Page 10: Image Compression: Coding and Decoding

Chain Coding

Assume the image contains only single-pixel-wide contours,like this, not this

After the initial point position, code direction only (3bits/step)

From Prof. Al Bovikcontour image

region image

0

1 2

3

4

5 6 7

= initial point

m

n

Code Stream:(3, 2), 1, 0, 1, 1, 1, 1, 3, 3, 3, 4, 4,

5, 4

initial point position chain code

Page 11: Image Compression: Coding and Decoding

Chain Coding

• Decoding Example

The chain code for a 8x8 binary image is given by:

Decode the image

(1, 6), 7, 7, 0, 1, 1, 3, 3, 3, 1, 1, 0, 7, 7

0

1 2

3

4

5 6 7

column row

decode

Page 12: Image Compression: Coding and Decoding

Chain Coding

• Decoding Example

The chain code for a 8x8 binary image is given by:

(1, 6), 7, 7, 0, 1, 1, 3, 3, 3, 1, 1, 0, 7, 7

0

1 2

3

4

5 6 7

column row

1 2 3 4 5 6 7 8123456781 2 3 4 5 6 7 8

12345678

decode

Page 13: Image Compression: Coding and Decoding

Lossless Gray-Scale Image Compression

Page 14: Image Compression: Coding and Decoding

Variable Word Length Coding

• Intuitive Idea– Assign short words to gray levels that occur

frequently– Assign long words to gray levels that occur

infrequently

• How Much Can Be Compressed?– Theoretical limit: entropy of the histogram– Practical algorithms (approach entropy):

Huffman coding, arithmetic coding

H I(k)

0 K-1gray level k

1

02 )(log)(

K

k

kpkp

Maximum entropy: Uniform distribution

Minimum entropy:Impulse (delta) distribution

typically in-between

From Prof. Al Bovik

Page 15: Image Compression: Coding and Decoding

Variable Word Length Coding: Example

• A 4x4 4bits/pixel original image is given by

2

8

8

6

6

8

6

8

8

10

8

9

10

14

10

10

0010 1000 0110 0110

0110 1000 1000 1000

1000 1000 1010 1010

1001 1010 1010 1110

Bit rate = 4bits/pixel

Total # of bits used to represent the

image:

4x16 = 64 bits

0: 00001: 00012: 00103: 00114: 01005: 01016: 01107: 01118: 10009: 100110: 101011: 101112: 110013: 110114: 111015: 1111

Default Code Book

encode

Page 16: Image Compression: Coding and Decoding

Variable Word Length Coding: Example

• Encode the original image with a CODE BOOK given left

0: 00000001: 00000012: 00013: 00000104: 00000115: 00001006: 017: 00001018: 109: 0010010: 1111: 000011012: 000011113: 00101014: 001115: 001011

2

8

8

6

6

8

6

8

8

10

8

9

10

14

10

10

0001 10 01 01

01 10 10 10

10 10 11 11

00100 11 11 0011

encode

Total # of bits used to represent the

image:

4+2+2+2+2+2+2+2+2+2+2+2+5+2+

2+4= 39 bits

Bit rate = 39/16= 2.4375 bits/pixel

CR = 64/39 = 1.6410

Huffman Code Book

Page 17: Image Compression: Coding and Decoding

Predictive Coding

• Intuitive Idea– Image pixels are highly correlated (dependent)– Predict the image pixels to be coded from those already

coded

• Differential Pulse-Code Modulation (DPCM)– Simplest form: code the difference between pixels

– Key features: Invertible, and lower entropy (why?)

H I(k) HD(k)

high entropy image reduced entropy imageK-10 K-11-K

image histogram (high entropy)

DPCM histogram (low entropy)

From Prof. Al Bovik

Original pixels:82, 83, 86, 88, 56, 55, 56, 60, 58,

55, 50, ……

DPCM:82, 1, 3, 2, -32, -1, 1, 4, -2, -3, -

5, ……

Page 18: Image Compression: Coding and Decoding

• Higher Order (Pattern) Prediction– Use both 1D and 2D patterns for prediction

• Apply Image Transforms before Predictive Coding– Decouple dependencies between image pixels

• Use Advanced Statistical Image Models– Better understanding of “the nature” of image structures

implies potentials of better prediction

Advanced Predictive Coding

1D Causal:

1D Non-causal:

2D Causal:

2D Non-Causal:

Page 19: Image Compression: Coding and Decoding

Lossy Gray-Scale Image Compression

Page 20: Image Compression: Coding and Decoding

Quantization

24 408 ... 248

21 3 4

Uniform scalar quantization:

Non-uniform scalar

quantization:

• Quantization: Widely Used in Lossy Compression– Represent certain image components with fewer bits

(compression)– With unavoidable distortions (lossy)

• Quantizer Design– Find the best tradeoff between

maximal compression minimal distortion

• Scalar Quantization

Page 21: Image Compression: Coding and Decoding

Quantization

Gray-level 1

Gray-level 2Vector quantization:

image component 2

image component 1

From Prof. Al Bovik

• Vector Quantization– Group multiple image components together form a

vector– Quantize the vector in a higher dimensional space– More efficient than scalar quantization (in terms of

compression)

Page 22: Image Compression: Coding and Decoding

• Block-Based Image Compression

• Transform-Domain Compression– Scalar or vector quantization of transform coefficients

(instead of image pixels)

Ideas on Lossy Image Compression

From Prof. Al Bovik

M x M M x M M x M

M x M M x M M x M

M x M M x M M x M

code each block

independently

imagePartition

Page 23: Image Compression: Coding and Decoding

Discrete Cosine Transform (DCT)

1

0

1

02 2

)12(cos

2

)12(cos),(

)()(4),(

N

m

N

n N

vn

N

umnmx

N

vCuCvuX

1

0

1

0 2

)12(cos

2

)12(cos),()()(),(

N

u

N

v N

vn

N

umvuXvCuCnmx

1,,11

02

1)(

Nu

uuC

where

N

2N

N

periodic extension by

DFT

reflected periodic

extension by DFT

• 2D-DCT:

• Inverse 2D-DCT:

• DFT vs. DCT

discontinuities: high frequencies continuou

s

From Prof. Al Bovik

Page 24: Image Compression: Coding and Decoding

2D-DCT

412

451

4253

4255

5153

5452

5152

5151414

432

4155

3654

5152

4851

5251

5050393

393

3751

4251

4951

5443

4949

4051412

374

3859

3566

4812

2534

2555

3655

13

42

12

09

40

21

13

4430

55

47

73

30

46

32

16113

916

109

621

179

3310

810

17201024

2727

132

6078

4413

1827

2738

56313

2D-DCT

image block

DCT block

low frequency

high frequency

low frequency

high frequency

DC component

Page 25: Image Compression: Coding and Decoding

JPEG Compression

169130

173129

170181

170183

179181

182180

179180

179179169132

171130

169183

164182

179180

176179

180179

178178167131

167131

165179

170179

177179

182171

177177

168179169130

165132

166187

163194

176116

15394

153183

160183

412

451

4253

4255

5153

5452

5152

5151414

432

4155

3654

5152

4851

5251

5050393

393

3751

4251

4951

5443

4949

4051412

374

3859

3566

4812

2534

2555

3655

- 128

13

42

12

09

40

21

13

4430

55

47

73

30

46

32

16113

916

109

621

179

3310

810

17201024

2727

132

6078

4413

1827

2738

56313

DCT

scalar quantization

zig-zag scan

00

00

00

00

00

00

00

0000

00

00

00

00

00

00

0000

00

00

01

10

11

01

1100

01

01

23

21

13

23

520

– Partition the image into 8x8 blocks, for each block

Page 26: Image Compression: Coding and Decoding

– Artifacts:Inside blocks: blurring (why?); Across blocks: blocking (why?)

Original: 100KB JPEG: 9KB JPEG: 5KB

JPEG Compression

– Adjust Quantization Step to Achieve Tradeoff between CR and distortion

Page 27: Image Compression: Coding and Decoding

Wavelet and JPEG2000 Compression• Wavelet Transform

Energy CompactionLower Entropy

Page 28: Image Compression: Coding and Decoding

• Bitplane Coding– Scan bitplanes

from MSB to LSB– Progressive (scalable)

JPEG (64:1) JPEG2000 (64:1)

s ssssss s ssssss s ssssss

0111 0 000000 0 000000

1 000011 0 000000 0 000000

1 1 000111 0 000000

111 1 000111

111

...

...

...

..........

...

...

1

sign

7

6

5

4

3

2

msb

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

Wavelet and JPEG2000 Compression