Vous êtes sur la page 1sur 82

Lecture 13

Image Compression

Why Do We Need Compression?


To reduce the volume of data to be transmitted (text, fax, images) To reduce the bandwidth required for transmission and to reduce storage requirements (speech, audio, video) The bit rate of uncompressed digital cinema data exceeds 1 Gbps
Lecture 13 - Image Compression

Why Do We Need Compression?


512

1 picture = 512x512x3 =786 KB 1 second = 786KB x 30 = 23.5 MB 512 1 minute = 23.5 MB x 60 = 1.4 GB 1 hour = 1.4 GB x 60 = 84 GB
Lecture 13 - Image Compression

Image Compression
Fundamentals aim to remove redundancy present in data in a way which makes image reconstruction possible. reduce the amount of data required to represent a digital image. transform a 2-D array into a statistically uncorrelated data set.

Lecture 13 - Image Compression

Image Compression
, : n1 n1 the number of information carrying units in two data sets that represent the same information => Relative data redundancy.

1 n1 RD = 1 CR : compression ratio = CR n1
data.

(i)n1= n1 , R = 1,RD = 1 => the first contains no redundant C (ii) n1<< n1CR ,RD 1 =>significant compression ,
highly redundant data.

(iii) n1>> n1, R 1 , RD C

=> the second data set contains more data than the original representation.
Lecture 13 - Image Compression

Why Do We Need Compression?

786488 bytes

Lecture 13 49746 bytes Image Compression Cr=15.8

How is compression possible?


Redundancy types Coding redundancy
to reduce the amount of data representing the same information.

Interpixel redundancy
including spatial redundancy, geometric redundancy and interframe redundancy

Psycho-visual Redundancy
certain information has less relative importance in normal visual processing and can be eliminated
Lecture 13 - Image Compression

Coding Redundancy
Suppose 1 1 h 1 be all the possible symbols, and Pr(ri) be the probability of its appearance. Let l(rk) be the number of bits used to represent the value of rk. Then the average number of bits required to represent each value is

r , r ,..., r

Lavg = l( rk ) Pr( rk )
k =1
8

h 1

Lecture 13 - Image Compression

Coding Redundancy
A Variable Length Coding Example

Lavg (Code2) = l2(rK) Pr(rK)


= 2(0.19)+2(0.25)+2(0.21)+3(0.16)+4(0.08)

+5(0.06)+6(0.03)+6(0.02) = 2.7 bits

Lecture 13 - Image Compression

Coding Redundancy

I 1(rk ) increases as

pr (rk ) decreases

the shortest code words in Code 2 are assigned to the grey levels that occurs most frequently in the image
Lecture 13 - Image Compression

10

Inter-pixel Redundancy
Also called spatial or geometric redundancy There is often correlation between adjacent pixels, i.e. the value of the neighbours of an observed pixel can often be predicted from the value of the observed pixel. run length coding

Lecture 13 - Image Compression

11

Psycho-visual Redundancy
The human visual system does not rely on quantitative analysis of individual pixel values when interpreting an image an observer searches for distinct features and mentally combines them into recognizable groupings In this process certain information is relatively less important than other this information is called psychovisually redudant

Lecture 13 - Image Compression

12

Psycho-visual Redundancy
Psychovisually redundant image information can be identified and removed a process referred to as quantization Quantization eliminates data and therefore results in lossy data compression Reconstruction errors introduced by quantization can be evaluated objectively or subjectively depending on the application need & specifications

Lecture 13 - Image Compression

13

Improved Gray-Scale Quantization


IGS ( improved gray scale ) quantization recognizes the eyes inherent sensitivity to edges and breaks them up by adding to each pixel a pseudo-random number. A sum-initially to zero-is first formed from the current 8-bit grey-level value and the four least significant bits of a previously generated sum. If the 4 most significant bits of the current value

111 11

are , however, is added instead. The 4 most significant bits of the resulting sum Lecture 13 - Image Compression are used as the coded pixel value.

11 1 11

14

Improved Gray-Scale Quantization

1111 Is maximum , Sum = Gray Level

If MSBi(1~4) of Gray Leveli =1111 then Sumi = Gray Leveli else Sumi = Gray Leveli + LSBi-1(5~8) of Sumi-1

Lecture 13 - Image Compression

15

Psycho-visual Redundancy

Lecture 13 - Image Compression

16

Quantization effects

Lecture 13 - Image Compression

17

Fidelity Criteria
f(x, y): an input image. f ( x , y ) :compressed output. error: e( x , y ) = f ( x , y ) f ( x , y ) total error: [ f ( x , y ) f ( x , y )] root mean square error:
MN 1 1 x= y= 1 1

erms

1 = MN

M 1 1 N x =1y =1

( x , y ) f ( x, y ) f
M 1 1 N x =1y =1 1

1 1 1

mean-square signal-to-noise ratio: f (x, y)


SNR
ms

= 1 log 1 1 1

M 1 1 N x =1y =1

[f ( x, y) f (x, y)]

Lecture 13 - Image Compression

18

Image Compression Model


A general compression system model
f ( x, y )

S o u rc e C h a n n e l C h a n n el S o u rc e C hannel f ( x, y ) encoder encoder decoder decoder

source encoder: remove input redundancies. Channel encoder: increase the noise immunity of the source encoders output.

Lecture 13 - Image Compression

19

Compression Model
The encoder is made up of a source encoder, which removes input redundancies, and a channel encoder, which increases the noise immunity of the source encoders output. If the channel between the encoder and decoder is noise free ( not prone to error), the channel encoder and decoder are omitted.

Lecture 13 - Image Compression

20

Compression Model
The source encoder is responsible for reducing or eliminating any coding, interpixel, or psychovisual redundancies in the input image. As the output of the source encoder contains little redundancy, it would be highly sensitive to transmission noise without the addition of the controlled redundancy-- channel encoding.

Lecture 13 - Image Compression

21

Image Compression Model


Source Encoder
f ( x, y )

M apper

Q u a n tiz e r

Sym bol E ncoder

C hannel

Source Decoder
C hannel Sym bol D ecoder In v e rse M a p p in g
f ( x, y )
Mapper: transform the input data into a(usually nonvisual) format designed to reduce interpixel redundancies in the input image. e.g. runlength coding. Quantizer: reduce the accuracy of the mappers output in accordance with some preestablished criterion fidelity. Symbol coder: create a fixed or variable length code to represent the quantizer output and maps the output in accordance with the code. e.g. 22 variable length encoding. Lecture 13 - Image Compression

Channel Encoder and Decoder


Hamming Code is an example of a code that can correct single errors. This code exists for many different word lengths. An example is the Hamming 7-4 Code, it consists of 3 information bits and 4 control bits, hence the code word consists of 11 bits. So, assume that we have the following information bits: b0,b1,b2,b3 The code word, consisting of the information bits and the four additional control bits
b3 b2 b1 h3 b0 h2 h1
Lecture 13 - Image Compression

23

Channel Encoder and Decoder


7-bit Hamming (7,4) code word h1h5 h6 h7 associated with a 4-bit binary number b3 b2 b1 b0 is h1 = b3b2 b0 h3 = b3 h5 = b2 h2 = b3 b1 b0 h6 = b1 1 1 h7 = b0 h4 = b2 b1 b0 1 1 b3 b2 b1 h4 b0 h2 h1 Then a single bit error is indicated by a nonzero parity word c4 c2 c1, where C1 = h1 1h3 h5 h7 1 1 C2 = h2 1h3 h6 h7 1 1 Lecture 13 - Image Compression C3 = h4 1h5 h6 h7 1 1

24

Lecture 13 - Image Compression

25

Classification
Lossless compression means that the data file is compacted without losing any information; that is, the file re-created from the compressed form is identical with the original. Lossy compression indicates that some, hopefully small, amount of information is lost in the compression process. The recreated file is very similar to, but not identical with, the original image. exploit both data redundancy and human perception properties
Lecture 13 - Image Compression

26

Lossless compression techniques


Run-length coding Huffman Coding Arithmetic Coding Lossless Predictive Coding

Lecture 13 - Image Compression

27

Run-length coding
replacing long sequences of the same value with a code indicating the value that is repeated and the number of times it occurs in the sequence. Input sequence: 0,0,-3,5,1,0,-2,0,0,0,0,2,-4,3,-2,0,0,0,1,0,0,-2 Run-length sequence: (2,-3)(0,5)(0,1)(1,-2)(4,2)(0,-4)(0,3)(0,-2)(3,1)(2,2)

Lecture 13 - Image Compression

28

Run-length coding
RLE compression is only efficient with files that contain lots of repetitive data. An image with many colors that is very busy in appearance, however, such as a photograph, will not encode very well. This is because the complexity of the image is expressed as a large number of different colors. And because of this complexity there will be relatively few runs of the same color.
Lecture 13 - Image Compression

29

Lossless compression techniques


Run-length coding Huffman Coding Arithmetic Coding Lossless Predictive Coding

Lecture 13 - Image Compression

30

Huffman Coding
When coding the symbols of an information source individually, Huffman coding yields the smallest possible number of code symbols per source symbol. The resulting code is optimal for a fixed value of n, subject to the constraint that the source symbols be coded one at a time.

Lecture 13 - Image Compression

31

Huffman Coding Steps


(i) Arrange the symbol probabilities in a decreasing order and consider them as leaf nodes of a tree. (ii) While there is more than one node: Merge the two nodes with smallest probability to form a new node whose probability is the sum of the two merged nodes. Arbitrarily assign 1 and 0 to each pair of branches merging into a node. (iii) Read sequentially from the root node to the leaf node where the symbol is located.
32

Lecture 13 - Image Compression

Example
A = {a1 a1, a1 a1, a1 , , } P (a1 = P(a1) = 1 ) .1 P (a1) = 1 .1 P (a1) = P(a1) = 1 .1

Lecture 13 - Image Compression

33

Example
1 0 0.6 0 0.4 0 1 0 0.2 1 1 1

a1(1 ) .1

a1 1 ) ( .1

a1(1 ) .1

a1(1 ) a1(1 ) .1 .1
Lecture 13 - Image Compression

34

Example

Huffman code

a2 a1 a3 a4 a5

0.4 0.2 0.2 0.1 0.1

1 01 000 0010 0011

1 2 3 4 4

0.4 0.4 0.6 0.4 0.4

2.2 bits/symbol

Lecture 13 - Image Compression

35

Lossless compression techniques


Run-length coding Huffman Coding Arithmetic Coding Lossless Predictive Coding

Lecture 13 - Image Compression

36

Arithmetic Coding
Arithmetic coding bypasses the idea of replacing an input symbol with a specific code. It replaces a stream of input symbols with a single floatingpoint output number. Arithmetic coding is especially useful when dealing with sources with small alphabets, such as binary sources, and alphabets with highly skewed probabilities.

Lecture 13 - Image Compression

37

Arithmetic Coding
(1)Get the probability and initial subinterval source symbol Source symbol a1 a2 a3 a4 Probability Initial subinterval 0.2 0.2 0.2 0.2 [0.0,0.2) [0.2,0.4) [0.4,0.8) [0.8,1.0)
38

Lecture 13 - Image Compression

(2)Use the initial subinterval of an to get the next encoding range

Arithmetic Coding

Lecture 13 - Image Compression

39

Arithmetic Coding
(3)Any number within the range [0.06752,0.0688) can be used. For example 0.068,can be used to represent the message.

Lecture 13 - Image Compression

40

Arithmetic Coding
Encoding algorithm for arithmetic coding. Low = 0.0 ; high =1.0 ; while not EOF do range = high - low ; read(c) ; high = low + range high_range(c) ; low = low + range low_range(c) ; End do output (low);
Lecture 13 - Image Compression

41

Arithmetic Decoding
Decoding is the inverse process. Since 0.06752 falls between 0.0 and 0.2, the first character must be a1. Removing the effect of a1 from 0.06752 by first subtracting the low value of a1, 0.0, giving 0.06752. Then divided by the width of the range of a1, 0.2. This gives a value of 0.3376.
Lecture 13 - Image Compression

42

Arithmetic Decoding
Then calculate where that lands, which is in the range of the next letter, a2. The process repeats until 0 or the known length of the message is reached.

Lecture 13 - Image Compression

43

Example
Symbol 1 1 1 probability 11 .1 11 .1 11 .1
1321

Range [1 , 1 ) .11.11 [1 , 1 ) .11.11 [1 , 1 ) .11.11

Suppose that we want to encode the message

Lecture 13 - Image Compression

44

Example
0.00 0.00 0.656
0.7712 0.7712

0.80 2 2 0.77408 0.82 0.656 3 3 1.00 0.80 0.80

0.7712

0.773504

0.77408

0.773504
45

Lecture 13 - Image Compression

Example
New character 1 3 2 1 Low value 0.0 0.0 0.656 0.7712 0.7712 High value 1.0 0.8 0.800 0.77408 0.773504

Lecture 13 - Image Compression

46

Example
Decoding:
r 0.7712 0.964 0.8 0 c 1[0.0,0.8) 0 3[0.82,1.0) 0.82 2[0.8,0.82) 0.8 1[0.0,0.8) 0

r_next=(r -Low)/range
low high 0.8 1.0 range 0.8 0.18
(0.7712-0)/0.8=0.964 (0.964-0.82) / 0.18=0.8 (0.8-0.8)/0.02=0

0.82 0.02 0.8

Symbol 1 1 1

Lecture 13 - Image Compression

probability 11 .1 11 .1 11 .1

Range [1 , 1 ) .11.11 [1 , 1 ) .11.11 [1 , 1 ) .11.11

47

Arithmetic Coding
In summary, the encoding process is simply one of narrowing the range of possible numbers with every new symbol. The new range is proportional to the predefined probability attached to that symbol. Decoding is the inverse procedure, in which the range is expanded in proportion to the probability of each symbol as it is extracted.

Lecture 13 - Image Compression

48

Lossless compression techniques


Run-length coding Huffman Coding Arithmetic Coding Lossless Predictive Coding

Lecture 13 - Image Compression

49

Lossless Predictive Coding


Predicting the next pixel value based on the previous value Encoding the difference between the predicted value and the actual value Differential pulse code modulation (DPCM)

Lecture 13 - Image Compression

50

Lossless Predictive Coding


A lossless predictive coding model: encoder
Input image


Predictor

Symbol encoder

Compressed image

Each successive pixel of the input image, denoted f n The output of the predictor is then rounded to the nearest integer, donated ^

fn

Lecture 13 - Image Compression

51

Lossless Predictive Coding


A lossless predictive coding model: decoder
Compressed image Symbol decoder

+
Predictor

Decompressed image

Lecture 13 - Image Compression

52

Lossless Predictive Coding


In most cases, however, the prediction is formed by a linear combination of m previous pixels. That is,

where m is the order of the linear predictor, round is a function used to denote the rounding or nearest integer operation, and the ai for i=1,2,3m are prediction coefficients.

Lecture 13 - Image Compression

53

Lossy Coding
Scalar Quantization Transform Coding Discrete Cosine Transform Wavelet Transform

Lecture 13 - Image Compression

54

Quantization

Input Quantizer

Output

The quantized output of f is f ^.The quantization erroe is f^-f

Lecture 13 - Image Compression

55

Lecture 13 - Image Compression

56

Quantization
Linear Quantizer Output codewords Non-linear Quantizer Output codewords

Input level

Input level

Lecture 13 - Image Compression

Encoder Convert transform coefficients into levels (Quantization) Decoder Convert levels into reconstructed transform coefficients (Inverse quantization)

Lecture 13 - Image Compression

58

Lecture 13 - Image Compression

59

Lecture 13 - Image Compression

60

Lecture 13 - Image Compression

61

Quantization
The amount of compression and the loss of image quality depend on the number of levels produced by the quantizer. A large number of levels Precision is only slightly reduced Low Compression A small number of levels Significant reduction in precision High compression
Lecture 13 - Image Compression

62

Transform Coding
At the heart of the majority of video coding system and standards. Spatial image data is inherently difficult to compress; neighboring samples are highly correlated (interrelated) and the energy tends to be evenly distributed across an image, making it difficult to discard data or reduce the precision of data without adversely affecting image quality.

Lecture 13 - Image Compression

63

Transform Coding System

Lecture 13 - Image Compression

64

Transform Coding
Compact the energy in the image Concentrate the energy into a small number of significant coefficients Decorrelate the data Minimizing the interdependencies between coefficients Discarding insignificant data has a minimal effect on image quality

Lecture 13 - Image Compression

65

Discrete cosine transform

Lecture 13 - Image Compression

66

Transform Coding
Discrete Fourier Transform (DFT) Use e j = cos + j sin as its basis functions Fast Fourier Transform (FFT) O(n logn) Not so popular in image compression because performance is not good enough computational load for complex number is heavy

Lecture 13 - Image Compression

67

Transform Coding
Discrete Cosine Transform (DCT) Use cosine function as its basis function Performance approaches KLT Fast algorithm exists Most popular in image compression application The periodicity implied by DCT implies that it causes less blocking effect than DFT Can be implemented by 2n points FFT Used in JPEG,H.26x,MPEG
Lecture 13 - Image Compression

68

Transform Coding
Transform of image efficiently puts most of the information into relatively few coefficients Quantizer: Bit allocation determine the number of bits for coding each coefficients. more bits are used for lower-frequency components.

Lecture 13 - Image Compression

69

Bit allocation
Bit allocation (cont.) Two ways of truncating coefficients 1. zonal coding - the retained coefficients are selected on the basis of maximum variance 2. threshold coding - selecting the coefficients according to the maximum magnitude of coefficients

Lecture 13 - Image Compression

70

Zonal coding Principle - according to the information theory, the transform coefficients with maximum variance carry most picture information and should be retained in the coding process. The process can be viewed as multiplying each transformed coefficient by the corresponding element in a zonal mask.
Lecture 13 - Image Compression

71

Zonal coding

1: retain 0: eliminate

Lecture 13 - Image Compression

72

Threshold coding Principle - the transform coefficients with largest magnitude contribute most to reconstructed subimage quality. The most often used adaptive transform coding approach due to its simplicity.

Lecture 13 - Image Compression

73

Three ways of threshold coding


1. a single global threshold for all subimages the compression ratio differs from image to image. 2. a different threshold for each subimage called N-largest coding, the same number of coefficients is discarded and so the coding rate is fixed.

Lecture 13 - Image Compression

74

Three ways of threshold coding


3. the threshold varies as a function of the location of each coefficient within the subimage results in a variable code rate and replace T(u, v) with

where Z(u, v) is an element of a normalization array Z


75

Lecture 13 - Image Compression

A typical normalization matrix Z(u, v) used by JPEG


Lecture 13 - Image Compression

76

Transform Coding Example


2-D DCT
m )u n )v ( 1 +1 ( 1 +1 F (u, v ) = C (u )C ( v ) f ( m, n ) cos cos , 1 N 1 N m =1 =1 n u , v = 1 , , N 1 ,1 ,
N 1 1 N

m )u n )v (1 + 1 (1 + 1 f ( m, n ) = C (u )C ( v ) F (u, v ) cos cos 1 , 1 N N u = 1v = 1 m, n = 1 , , N 1 ,1 ,


N 1 1 N

where C (u ), C ( v ) = 1 N , /

for u, v = 1 ;

C (u ), C ( v ) = 1 N , otherwise. /
Lecture 13 - Image Compression

8x8 DCT

Lecture 13 - Image Compression

8x8 DCT
DC coefficient DCT AC coefficients

8x8 image block

DCT coefficients
Low frequencies Medium frequencies High frequencies Lecture 13 - Image Compression

79

8x8 DCT
52 63 62 63 67 79 85 87 55 59 59 58 61 65 71 79 61 66 68 71 68 60 64 69 66 90 113 122 104 70 59 68 70 61 109 85 144 104 154 106 126 88 77 68 55 61 65 76 64 69 66 70 68 58 65 78 73 72 73 69 70 75 83 94

Pixel domain

DC

DCT

IDCT

AC

609 - 29 - 62 25 55 - 20 - 1 3 7 - 21 - 62 9 11 - 7 - 6 6 - 46 8 77 - 25 - 30 10 7 - 5 - 50 13 35 - 15 - 9 6 0 3 11 - 8 - 13 - 2 - 1 1 -4 1 - 10 1 3 -3 -1 0 2 -1 -4 -1 2 -1 2 -3 1 -2 -1 -1 -1 -2 -1 -1 0 -1

Frequency domain

Lecture 13 - Image Compression

8x8 DCT Basis Functions


dc
Low frequencies Medium frequencies High frequencies

Lecture 13 - Image Compression

Example

Lecture 13 - Image Compression

82

Vous aimerez peut-être aussi