scalar quantization - oregon state...

35
Lecture 12: Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon State University

Upload: others

Post on 07-Apr-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Lecture 12:Lossy Image Compression and

Scalar Quantization

Thinh NguyenOregon State University

Page 2: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Lossy Image Compression Techniques

Scalar quantization (SQ)

Vector quantization (VQ)

Discrete Cosine Transform (DCT) Compression:JPEG

Wavelet Compressions:SPIHTEBCOT

Page 3: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Lossy Image Compression Techniques

SPIHT

(Set Partition Hierarchy Tree)

Original JPEG

32:1 compression

Page 4: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Images and the EyeImages are meant to be viewed by the human eye.

The eye is very good at “interpolation,” that is, the eye can tolerate some distortion. So lossy compression is not necessarily bad.

Page 5: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Distortion

Page 6: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

DistortionPeak Signal to Noise Ratio (PSNR) is the tandard way to measure fidelity.

PSNR is measured in decibels (dB):0.5 to 1 dB is said to be a perceptible difference.Decent images start at about 25-30 dB.35-40 dB might be indistinguishable from the original

Page 7: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

PSNR is not everything!

Page 8: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Distortion vs. Compression

Page 9: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Quantization Problem

Analog signals

sampling quantization

Digital signals

A/D converterDigital Signal processing

D/A converter

Analog signals

Real-world signals are continuous!

Signal representation in computer is discrete with finite precision!

Higher precision requires larger storage

Page 10: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Scalar Quantization Problems

Problem 1:You’re given 16-bit integers (0-65545). Unfortunately, you only have space to store 8-bit integers (0-255).

Come up with a representation of those 16-bit integers that uses only 8 bits!

Problem 2:You have a string of those 8-bit integers that use your representation.

Recreate the 16-bit integers as best you can!

Page 11: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Scalar Quantization

Page 12: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Scalar Quantization Strategies

Build a codebook with a training set, then always encode and decode with that fixed codebook.

Most common use of scalar quantization.

Build a codebook for each image and transmit the codebook with the image.Training can be slow.

Page 13: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Distortion from Scalar Quantization

Page 14: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Uniform Quantization Example

Page 15: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Uni. Quant. Encoder and Decoder

Page 16: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Improve Bit Rate

Page 17: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Example

Page 18: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Improve Distortion

Page 19: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Example

Page 20: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Extreme Case

Page 21: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Quantization Examples: Mandrill

8 bit quantization 4 bit quantization 3 bit quantization

Page 22: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Quantization Examples: Pepper

8 bit quantization 4 bit quantization 3 bit quantization

Page 23: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Non-uniform scalar quantization

Page 24: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Non-uniform scalar quantizationProblem: Given M reconstruction levels, find the boundaries of these construction levels (b1,b2, … bM) and reconstruction levels (y1,y2, … yM) to minimize the distortion.

b1 b2 b3 b4b-4 b-3 b-2 b-1

y1

y2

y3

y-2

y-3

Input x

Page 25: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Non-uniform scalar quantizationLLoyd (1957) shows that the solutions yi and bi must satisfy the following 2 conditions:

−=j

j

j

j

b

b

b

bj

dxxf

dxxxf

y

1

1

)(

)(

21 jj

j

yyb

+= +

input x offunction density y probabilit theis :)(xf

Page 26: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Non-uniform scalar quantizationProof: Take derivatives of with respect to yi and biof MSE, setting the result to zero, and solve for yiand bi

∑ ∫=

−=M

i

b

bi

j

j

dxxfyxMSE1

2

1

)()(

Page 27: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Lloyd’s AlgorithmLloyd (1957)Creates an optimized (but probably not optimal) codebook of size n.Let px be the probability of pixel value x.

Probabilities is either known or might come from a training set.Given codewords c(0),c(1),...,c(n-1) and pixel x. Let index(x) be the index of the closest code word to x.Expected distortion is

Goal of the Lloyd algorithm is to find the codewords that minimize distortion.

Lloyd finds a local minimum by an iteration process.

Page 28: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Lloyd’s Algorithm

Page 29: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Example

Page 30: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Example

Page 31: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Example

Page 32: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Example

Page 33: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Example

Page 34: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Example

Page 35: Scalar Quantization - Oregon State Universityweb.engr.oregonstate.edu/~thinhq/teaching/ece499/spring06/lossy_q… · Lossy Image Compression and Scalar Quantization Thinh Nguyen Oregon

Scalar Quantization NotesUseful for analog to digital conversion.

With entropy coding, it yields good lossy compression.

Lloyd algorithm works very well in practice, but can take many iterations.

For n codewords should use about 20n sizerepresentative training set.Imagine 1024 codewords.