You are on page 1of 3

Image Compression

Lossless (e.g. :: .jpeg file format)

Lossy (e.g. :: .au, .png file format)

Lossless compression algorithm ::

i) Runlength algorithm.
ii) Variable length coding (Huffman coding).
iii) LZW coding.

Runlength Algorithm ::

A5B5C7X3D3 Compressed Data

This algorithm consists of replacing large sequences of repeating data with only one item of this
data followed by a counter showing how many times this item is repeated.
Huffman coding ::

Step 1 :: Create a leaf node for each unique character and build a min heap of all leaf nodes .
Step 2 :: Extract two nodes with the minimum frequency from the min heap.
Step 3 :: Create a new internal node with frequency equal to the sum of the two nodes
frequencies. Make the first extracted node as its left child and the other extracted node as its
right child. Add this node to the min heap.
Step 4 :: Repeat step2 and step3 until the heap contains only one node. The remaining node is
the root node and the tree is complete.

Example ::-

Symbol Probability Bit per symbol

A 0.12 000 3 bits
B 0.04 001 3 bits
C 0.45 010 3 bits
D 0.16 011 3 bits
E 0.23 100 3 bits
14 bits
(in total)
Huffman tree ::
0 1.0 1
0.45 0 0.55 1
0.23 0 0.32 1

0 0.16 1 0.16

0.4 0.12

Huffman code according to the tree ::

A 1011 4 bits
B 0011 4 bits
C 0 1 bit
D 111 3 bits
E 01 2 bits
14 bits in total

Compression Percentage ::

(Total number of bits total number of bit of Huffman code)

x 100
Total number of bits

1514
thus, x 100 = 6.66 %
15
LZW coding ::

Dictionary of previously scan.

It codes group of character of varying length.

Algorithm ::

i) The source sequence is sequentially parsed into string that have not appeared so far.
ii) After every separation, we look along the input sequence until we come to the shortest
string that has not been marked before.
iii) We code this phase bygiving the location of the prefix and value for last bit.

Example ::

Let A=0 and B=1,

Partition 1 2 3 4 5 6 7 8 9
Sequence A AA ABB B ABA ABAB BB ABBA BB
Numerical representation A 1B 2B B 2A 5B 4B 3A 7
code 0,0 1,1 10,1 0,1 10,0 101,1 100,1 11,0 1

For code generation every number is converted to its corresponding binary value.