©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data...

38
©Brooks/Cole, 2003 Chapter 15 Data Compression

Transcript of ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data...

Page 1: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Chapter 15

Data Compression

Page 2: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Realize the need for data compression.Realize the need for data compression.

Differentiate between lossless and lossy compression.Differentiate between lossless and lossy compression.

Understand three lossless compression encoding Understand three lossless compression encoding techniques: run-length, Huffman, and Lempel Ziv.techniques: run-length, Huffman, and Lempel Ziv.

After reading this chapter, the reader should After reading this chapter, the reader should be able to:be able to:

OOBJECTIVESBJECTIVES

Understand two lossy compression methods: JPEG andUnderstand two lossy compression methods: JPEG andMPEG.MPEG.

Page 3: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-1

Data compression methodsData compression methods

Data compressionData compression means sending or means sending or storing a storing a smaller smaller number of bits.number of bits.

Page 4: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

LOSSLESSLOSSLESSCOMPRESSIONCOMPRESSION

METHODSMETHODS

LOSSLESSLOSSLESSCOMPRESSIONCOMPRESSION

METHODSMETHODS

15.115.1

Page 5: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Lossless compressionLossless compression

In lossless data compression, the integrity of the In lossless data compression, the integrity of the data is preserved.data is preserved.

The original data and the data after compression The original data and the data after compression and decompression are and decompression are exactly the sameexactly the same because the compression and decompression because the compression and decompression algorithms are algorithms are exactly the inverse of each otherexactly the inverse of each other..

Example:Example: Run-length encodingRun-length encoding Huffman encodingHuffman encoding Lempel Ziv (L Z) encoding (dictionary-based encoding)Lempel Ziv (L Z) encoding (dictionary-based encoding)

Page 6: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-2

Run-length encodingRun-length encoding

It does It does notnot need knowledge of the need knowledge of the frequency of occurrence of symbols and frequency of occurrence of symbols and can be very can be very efficientefficient if data are if data are represented as 0s and 1s.represented as 0s and 1s.

For example:For example:

Page 7: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-3

Run-length encoding for two symbolsRun-length encoding for two symbols

We can encode We can encode one symbolone symbol which is more which is more frequent than the other.frequent than the other.

This example only encode 0’s between 1’s.This example only encode 0’s between 1’s.

There is no 0 between 1’s

Page 8: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Table 15.1 Frequency of charactersTable 15.1 Frequency of characters

CharacterCharacter A A B B C C D D E E------------------------------------------------------Frequency 17 12 12 27 32

Huffman codingHuffman coding

In Huffman coding, you assign In Huffman coding, you assign shorter shorter codescodes to symbols that occur to symbols that occur more more frequentlyfrequently and longer codes to those that and longer codes to those that occur less frequently.occur less frequently.

For example:For example:

Page 9: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-4

Huffman coding

Page 10: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-5

Final tree and code

Page 11: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-6

Huffman encoding

Page 12: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-7

Huffman decoding

Page 13: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Huffman codingHuffman coding

The beauty of Huffman coding is that The beauty of Huffman coding is that no code in no code in the prefix of another code.the prefix of another code.

There is There is no ambiguityno ambiguity in encoding. in encoding.

The receiver can decode the received dataThe receiver can decode the received data without ambiguitywithout ambiguity..

Huffman code is called Huffman code is called instantaneous (instantaneous ( 即時的即時的 ) ) codecode because the decoder can unambiguously because the decoder can unambiguously decode the bits instantaneously with the decode the bits instantaneously with the minimum number of bits.minimum number of bits.

Page 14: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Lempel Ziv encodingLempel Ziv encoding

LZ encoding is an example of a category LZ encoding is an example of a category of algorithms called of algorithms called dictionary-baseddictionary-based encoding.encoding.The The ideaidea is to create a dictionary ( is to create a dictionary (tabletable) of ) of strings used during the communication strings used during the communication session.session.The compression algorithm extracts the The compression algorithm extracts the smallest substringsmallest substring that cannot be found in that cannot be found in the dictionary from the remaining non-the dictionary from the remaining non-compressed string.compressed string.

Page 15: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-8:Part I

Example of Lempel Ziv encoding

Page 16: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-8:Part 2

Example of Lempel Ziv encoding

Page 17: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-9: Part I

Example of Lempel Ziv decoding

Page 18: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-9: Part II

Example of Lempel Ziv decoding

Page 19: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

LOSSYLOSSYCOMPRESSIONCOMPRESSION

METHODSMETHODS

LOSSYLOSSYCOMPRESSIONCOMPRESSION

METHODSMETHODS

15.215.2

Page 20: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Lossy compression methodsLossy compression methods

Loss of information is acceptable in a Loss of information is acceptable in a picture of video.picture of video.The The reasonreason is that our eyes and ears is that our eyes and ears cannot distinguish subtle changes.cannot distinguish subtle changes.Loss of information isLoss of information is not not acceptable in a acceptable in a text file or a program file.text file or a program file.For examples:For examples: Joint photographic experts group (Joint photographic experts group (JPEGJPEG)) Motion picture experts group (Motion picture experts group (MPEGMPEG))

Page 21: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-10

JPEG gray scale example, 640 x 480 pixels

Image compression: JPEGImage compression: JPEG

Page 22: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-11

JPEG process

DTC: discrete cosine transformDTC: discrete cosine transform

QuantizationQuantization

Compression Compression

Page 23: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-12

Case 1: uniform gray scale

Discrete cosine transformDiscrete cosine transform

TT(0, 0): DC value (direct current value)(0, 0): DC value (direct current value)TT((m, nm, n) : AC values (represent changes in the pixel values)) : AC values (represent changes in the pixel values)

T(0, 0)

Page 24: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-13

Case 2: two sections

Discrete cosine transformDiscrete cosine transform

Page 25: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-14

Case 3: gradient gray scale

Discrete cosine transformDiscrete cosine transform

Page 26: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

DCT discussionDCT discussionThe DCT transformation creates table The DCT transformation creates table TT from table from table PP..The The DCDC value gives the value gives the average valueaverage value of of the pixels.the pixels.The The ACAC values gives the values gives the changeschanges..Lack of changes in neighboring pixels Lack of changes in neighboring pixels creates 0s.creates 0s.The DCT transformation is The DCT transformation is reversiblereversible..Appendix FAppendix F (Mathematical formula for (Mathematical formula for DCT transformation)DCT transformation)

Page 27: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

QuantizationQuantization

After the After the TT table is created, the values are table is created, the values are quantized to quantized to reduce the number of bitsreduce the number of bits needed for encoding.needed for encoding.

Quantization:Quantization: Divide the number by a constant and then Divide the number by a constant and then

drop the fraction.drop the fraction. The quantizing phase is The quantizing phase is not not reversible.reversible. Some information will be lost.Some information will be lost.

Page 28: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

CompressionCompression

After quantization, the values are read After quantization, the values are read from the table, and from the table, and redundant 0sredundant 0s are are removed.removed.

The reason is that if the picture does not The reason is that if the picture does not have fine changes, the have fine changes, the bottom right cornerbottom right corner of the of the TT table is all table is all 0s 0s..

Fig. 15.15Fig. 15.15

Page 29: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-15

Reading the table

Page 30: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

品質 :100%

Page 31: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

品質 :50%

Page 32: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

品質 :10%

Page 33: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

品質 :5%

Page 34: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Video compression--MPEGVideo compression--MPEG

MPEG methodMPEG method Spatial compressionSpatial compression

The spatial compression of each frame is The spatial compression of each frame is done with done with JPEGJPEG..

Temporal compressionTemporal compression

The temporal compression removes the The temporal compression removes the redundant frames.redundant frames.

MPEG method first divides frames into MPEG method first divides frames into three categories: three categories: I-frames, P-frames, B-I-frames, P-frames, B-framesframes..

Page 35: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-16

MPEG frames

I-framesI-frames: (intra-coded frame): (intra-coded frame) It is an independent frame that isIt is an independent frame that is not not related related

to any other frame.to any other frame. They are present at They are present at regular intervalsregular intervals. . I-frames are independent of other frames and I-frames are independent of other frames and

cannotcannot be constructed from other frames. be constructed from other frames.

Page 36: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-16

MPEG frames

P-framesP-frames: (predicted frame): (predicted frame) It is related to the preceding I-frame or P-frame.It is related to the preceding I-frame or P-frame. Each P-frame contains only the Each P-frame contains only the changeschanges from the from the

preceding frame.preceding frame. P-frames can be constructed P-frames can be constructed onlyonly from previous I- or from previous I- or

P-frames.P-frames.

B-framesB-frames: (bidirectional frame): (bidirectional frame) It is relative to the preceding and following I-frame or It is relative to the preceding and following I-frame or

P-frame.P-frame. Each B-frame is relative to the past and the future.Each B-frame is relative to the past and the future. A B-frame is never related to another B-frame.A B-frame is never related to another B-frame.

Page 37: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Figure 15-17

MPEG frame construction

Inpu

t seq

uenc

e

MP

EG

seq

uen

ce

Page 38: ©Brooks/Cole, 2003 Chapter 15 Data Compression. ©Brooks/Cole, 2003 Realize the need for data compression. Differentiate between lossless and lossy compression.

©Brooks/Cole, 2003

Key termsKey termsAC valueAC valueB-frameB-frameBinary treeBinary treeBranchBranchCompressionCompressionData compressionData compressionDC valueDC valueDecoding decompressionDecoding decompressionDictionary-based Dictionary-based encodingencodingDCTDCTHuffman codingHuffman codingI-frameI-frame

JPEGJPEGLZ encodingLZ encodingLossless data Lossless data compressioncompressionLossy data compressionLossy data compressionMPEGMPEGNode Node P-frameP-frameQuantizationQuantizationRun-length encodingRun-length encodingSpatial compressionSpatial compressionTemporal compressionTemporal compression