Digital Image Processing Lecture 21 Lossy Compression Prof

  • Slides: 26
Download presentation
Digital Image Processing Lecture 21: Lossy Compression Prof. Charlene Tsai 1

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

Reminder … n The Thursday class (5/29) is moved to Monday (5/28) for next

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

JPEG Algorithm n n n Lossy compression trades some acceptable data loss for greater

JPEG Algorithm n n n 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. 3

Transform n n n Discrete Cosine Transform (DCT) Applying to 8 x 8 blocks,

Transform n n n Discrete Cosine Transform (DCT) Applying to 8 x 8 blocks, the forward and inverse DCT are real-valued, high informationpacking capability, and separable. 4

Comparison with FFT n n n Given the following sequence 10 25 40 55

Comparison with FFT n n n 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 5

JPEG Compression n For each 8 x 8 image block, perform the compression q

JPEG Compression n For each 8 x 8 image block, perform the compression q q q Subtracting 128 from each value Apply DCT Normalization by dividing by matrix Q (the lossy part) n q Turning most of the elements zero Change the matrix into a vector by reading the nonzero element in a zigzag fashion. O O O … … … 6

(con’d) n The first element (DC coefficient) of the vector is encoded as the

(con’d) n The first element (DC coefficient) of the vector is encoded as the difference between itself and the DC of previous block. q q n n 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 7

Decompression n Inverse the operations: q q q Decode Huffman encoding and RLE Put

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

The Lossless Parts n n Huffman Coding and RLE for AC and DC terms,

The Lossless Parts n n Huffman Coding and RLE for AC and DC terms, respectively. We’ll focus the discussion on the AC terms q q q Each nonzero value x is assigned a category k The number of preceding 0 s (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 9

Huffman Code Table n n Part of JPEG baseline standard See the handout for

Huffman Code Table n n Part of JPEG baseline standard See the handout for the code table and application. 10

Wavelet Transform n n n For both FT and DCT, we assume so kind

Wavelet Transform n n n 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 wavelet 11

What to do with a wavelet? n Given a wavelet function q q q

What to do with a wavelet? n Given a wavelet function q q q n , 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 12

Applications n n n Noise reduction Edge detection Compression q Adopted by JPEG 2000

Applications n n n Noise reduction Edge detection Compression q Adopted by JPEG 2000 13

A Simple Wavelet Transform n n All wavelet transform work by taking weighted averages

A Simple Wavelet Transform n n 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. q If a and b are two numbers, we get average s and difference d by: 14

(cont) n Given a simple vector v of 8 elements, we create two new

(cont) n Given a simple vector v of 8 elements, we create two new vectors v 1 and v 2 of 4 elements each: q q n n n v 1 containing the averages v 2 containing the differences DWT at 1 scale is: We can keep going for another 2 levels. Let’s go through the example in pg 425 of the handout. (available online) 15

Haar Wavelet n Simplest wavelet, defined as n Haar wavelet can be written in

Haar Wavelet n Simplest wavelet, defined as n Haar wavelet can be written in terms of a simpler pulse function 16

Mother wavelet Father wavelet (scaling function) 17

Mother wavelet Father wavelet (scaling function) 17

Discrete Wavelet transform n The forward transformation n The inverse is 18

Discrete Wavelet transform n The forward transformation n The inverse is 18

n n are called the filter coefficients (or taps) A wavelet is completely specified

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

Back to Haar Wavelet Low pass High pass n n n where values are

Back to Haar Wavelet Low pass High pass n n n where values are what we have in a DWT matrix Let’s look at the example in pg 429. 20

Two-Dimensional Wavelet (STD) 21

Two-Dimensional Wavelet (STD) 21

Two-Dimensional Wavelet (non. STD) 22

Two-Dimensional Wavelet (non. STD) 22

Example: one scale 23

Example: one scale 23

Image Compression n For a given value d, set all values x in the

Image Compression n For a given value d, set all values x in the DWT for which to 0. 24

High-Pass Filtering n n Except from the top left image, the rest is highfrequency

High-Pass Filtering n n Except from the top left image, the rest is highfrequency information. If setting the top-left corner to 0, the result after inversion would be a high-pass filtered image. 25

Denoising n n Very similar to compression by using thresholding. An example is given

Denoising n n Very similar to compression by using thresholding. An example is given in pg 446. 26