Docsity

Engineering Mathematics II: Compression Algorithms, Slides of Electrical Engineering

Partial preview of the text

Download Engineering Mathematics II: Compression Algorithms and more Slides Electrical Engineering in PDF only on Docsity!

Engineering Mathematics II

Outline

• Lossless Compression

– Huffman & Shannon-Fano

– Arithmetic Compression

– The LZ Family of Algorithms

• Lossy Compression

– Fourier compression

– Wavelet Compression

– Fractal Compression

Run Length Encoding

Original Data

String

Encoded Data

String

Guns

Butter

Guns¤

<10>Butter

Relative Encoding

• Useful when there are sequences of runs of data

that vary only slightly from one run to the next:

– eg the lines of a fax

– The position of each change is denoted relative to the

start of the line

– Position indicator can be followed by a numeric count

indicating the number of successive changes

– For further compression, the position of the next change

can be denoted relative to the previous

Huffman Encoding

• Arrange the character set in order of decreasing

probability

• While there is more than one probability class:

– Merge the two lowest probability classes and add their

probabilities to obtain a composite probability

– At each branch of the binary tree, allocate a '0' to one

branch and a '1' to the other

• The code for each character is found by traversing

the tree from the root node to that character

Huffman Encoding

Character X X X X X X X

Probability

Character X X X X X X X

Probability 00 010 011 100 101 110 111

Shannon-Fano Encoding

Character X X X X X X X

Probability

Code 11 10 011 010 001 0001 0000

Arithmetic Coding

• Arithmetic coding assumes there is a model for

statistically predicting the next character of the

string to be encoded

– An order-0 model predicts the next symbol based on its

probability, independent of previous characters

• For example, an order-0 model of English predicts the

highest probability for ‘e’

– An order-1 model predicts the next symbol based on the

preceding character

• For example, if the preceding character is ‘q’, then ‘u’ is a

likely next character

– And so on for higher order models

• ‘ert’ ‘erty’, etc. Docsity.com

Arithmetic Coding

X7 0.

  • •
  • X1 0. Character Probability
  • X2 0.
  • X3 0.
  • X4 0.
  • X5 0.
  • X6 0.
  • X7 0.

Arithmetic Coding

• Suppose we want to encode the string X1X3X

– After X1, our interval is [0,0.1]

– After X3, it is [0.015,0.035]

– After X7, it is [0.033,0.035]

• The natural output to choose is the shortest binary

fraction in [0.033,0.035]

• Obviously, the algorithm as stated requires infinite

precision

• Slight variants re-normalise at each stage to

remain within computer precision Docsity.com

LZW

• LZW is an LZ78-based scheme designed by T

Welch in 1984

– LZ78 schemes work by putting phrases into a dictionary

• when a repeat occurrence of a particular phrase is found,

outputting the dictionary index instead of the phrase

– LZW starts with a 4K dictionary

• entries 0-255 refer to individual bytes

• entries 256-4095 refer to substrings

– Each time a new code is generated it means a new

string has been parsed

• New strings are generated by adding current character K

to the end of an existing string w (until dictionary is full)Docsity.com

LZW Algorithm

set w = NIL

loop

read a character K

if wK exists in the dictionary

w = wK

else

output the code for w

add wK to the string table

w = K

endloop

Lossy Compression

• Lossy compression algorithms do not guarantee to

reproduce the original input

– They achieve much higher compression by limiting their

compression to what is ‘near enough’ to be acceptably

detectable

• Usually, this means detectable by a human sense - sight

(jpeg), hearing (mp3), motion understanding (mp4)

– This requires a model of what is acceptable

• The model may only be accurate in some circumstances

  • Which is why compressing a text or line drawing with jpeg is a

bad idea

Fourier Compression (jpeg)

• The Fourier transform of a dataset is a frequency

representation of that dataset

– You have probably already seen graphs of Fourier

transforms

• the frequency diagram of a sound sample is a graph

representation of the Fourier transform of the original

data, which you see graphed as the original

time/amplitude diagram