Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

26
Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai

Transcript of Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

Page 1: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

Digital Image Processing Lecture 21: Lossy

Compression

Prof. Charlene TsaiProf. Charlene Tsai

Page 2: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

2

Reminder …

The Thursday class (5/29) is moved to Monday (5/28) for next week.

Page 3: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

3

JPEG Algorithm

Lossy compression trades some acceptable data loss for greater rate of compression.

There are many available, but the most popular is the one developed by JPEG – transform coding.

Coding not done on pixel values, but on a transform.

Page 4: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

4

Transform

Discrete Cosine Transform (DCT) Applying to 8x8 blocks, the forward and

inverse DCT are

DCT are real-valued, high information-packing capability, and separable.

16

12cos

16

12cos,

4,

7

0

7

0

vkujkjf

vCuCvuF

j k

16

12cos

16

12cos,,

7

0

7

0

vkujvCuCvuFjif

u v

Page 5: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

5

Comparison with FFT

Given the following sequence

10 25 40 55 70 85 100 115 If using FFT, the inverse of the first 4 FFT

coefficients gives

49 41 56 57 71 70 85 90 If using DCT, the result is

11 23 41 56 69 84 102 114

Page 6: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

6

JPEG Compression

For each 8x8 image block, perform the compression Subtracting 128 from each value Apply DCT Normalization by dividing by matrix Q (the lossy part)

Turning most of the elements zero Change the matrix into a vector by reading the

nonzero element in a zigzag fashion. O O O …

O O O …

O O O …

… … … …

Page 7: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

7

(con’d)

The first element (DC coefficient) of the vector is encoded as the difference between itself and the DC of previous block. Keeps all values (except the very first one) small Compressed using RLE

Other values (AC coefficients) are compressed using Huffman coding

Rate of compression is controlled by scaling Q => more scaling, more compression

Page 8: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

8

Decompression

Inverse the operations: Decode Huffman encoding and RLE Put the vector back to 8x8 matrix Multiply by Q Inverse DCT Shift back by 128

Page 9: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

9

The Lossless Parts

Huffman Coding and RLE for AC and DC terms, respectively.

We’ll focus the discussion on the AC terms Each nonzero value x is assigned a category k

The number of preceding 0s (run). Values: 7 -1 10 0 2 1 0 0 2 4 0 1 0 -1 Category: 1 4 2 1 2 3 1 1 Run: 0 0 1 0 2 0 1 1

122 1 kk x

Page 10: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

10

Huffman Code Table

Part of JPEG baseline standard See the handout for the code table and

application.

Page 11: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

11

Wavelet Transform

For both FT and DCT, we assume so kind of periodicity in the image.

Wavelet Transform keeps the wave concept, but drop the eriodicity.

Wavelet is a little part of a wave

wave wavelet

Page 12: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

12

What to do with a wavelet?

Given a wavelet function , we can Dilate it by applying a scaling factor to x.

e.g. would squash and would expand.

Translate by adding/subtracting a value from x. e.g. shift the wavelet 2 to the right, and shift 3 to the left.

Change it height by multiplying the function by a constant.

All together, we get

xwf

xwf 2 2xwf

2 xwf 3 xwf

cbxaw

Page 13: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

13

Applications

Noise reduction Edge detection Compression

Adopted by JPEG2000

Page 14: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

14

A Simple Wavelet Transform

All wavelet transform work by taking weighted averages of input values and providing extra information for inversion.

Here the example is: averaging of two values and differencing. If a and b are two numbers, we get average s and

difference d by:

sadba

s

;2

Page 15: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

15

(cont)

Given a simple vector v of 8 elements, we create two new vectors v1 and v2 of 4 elements each: v1 containing the averages v2 containing the differences

DWT at 1 scale is: We can keep going for another 2 levels. Let’s go through the example in pg425 of the

handout. (available online)

211 ,vvd

Page 16: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

16

Haar Wavelet

Simplest wavelet, defined as

Haar wavelet can be written in terms of a simpler pulse function

otherwise0

121 if1

210 if1

x

x

x

otherwise0

10 if1 xx

Page 17: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

17

Mother wavelet Father wavelet (scaling function)

122 xxx 122 xxx

Page 18: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

18

Discrete Wavelet transform

The forward transformation

The inverse is

xxfM

kjW

xxfM

kjW

kjx

kjx

,

,0

1,

1,

0

xkjWM

xkjWM

xf kjjj

kjk

,,0

0

0,

1,

1

Page 19: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

19

are called the filter coefficients (or taps) A wavelet is completely specified by its taps.

ih

Page 20: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

20

Back to Haar Wavelet

where values are what we have in a DWT matrix Let’s look at the example in pg 429.

122

122

01

10

xhxhx

xhxhx

2110 hh

ih

Low pass

High pass

Page 21: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

21

Two-Dimensional Wavelet (STD)

Page 22: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

22

Two-Dimensional Wavelet (non-STD)

Page 23: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

23

Example: one scale

Page 24: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

24

Image Compression

For a given value d, set all values x in the DWT for which to 0.dx

Page 25: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

25

High-Pass Filtering

Except from the top left image, the rest is high-frequency information.

If setting the top-left corner to 0, the result after inversion would be a high-pass filtered image.

Page 26: Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai.

26

Denoising

Very similar to compression by using thresholding.

An example is given in pg446.