2. Compression:
It is a process of reducing size by encoding it’s information
more efficiently.
Due to this there is a reduction in the number of bits and bytes
used to store the information.
A smaller file size is generated in order to achieve a faster
transmission of electronic files and a smaller space required
for its downloading.
3. LZW compression:
LZW is the first letter of the names of the scientists Abraham
Lempel, Jakob Ziv, and Terry Welch, who developed this
algorithm.
Is a lossless compression algorithm.
It is simple and is dictionary based.
4. Working of LZW compression:
It is a simple process.
It replaces strings of characters with single codes.
A new string of characters is added every time it sees to a
table of strings.
Compression occurs when a single code is output instead of a
string of characters.
The first 256 codes are by default assigned to the standard
character set.
5. Continue…
Starts with a dictionary of all the single characters and
gradually builds the dictionary as the information is sent
through.
Lossless compression hence works good for text compression.
Uses a code table with 4096 as a common choice for number
entries.
6. Why to use LZW compression:
Two reasons . . .
For most palette color images LZW yields the highest
compression efficiency without sacrificing image data.
The GIF image file format is the de facto standard for images
on the web. Most GIF files use the LZW compression.
7. LZW Algorithm:
The LZW Compression Algorithm can summarised as follows:
w = NIL;
while ( read a character k )
{
if wk exists in the dictionary
w = wk;
else
add wk to the dictionary;
output the code for w;
w = k;
}
8. LZW Encoding:
If the message to be encoded consists of only one character,
LZW outputs the code for this character; otherwise it inserts
two-or multi-character, overlapping.
The last character of a pattern is the first character of the next
pattern.
9. LZW Encoding algorithm:
Prefix←first input character;
CodeWord←256;
while(not end of character stream)
{ Char← next input character;
if(Prefix+ Char exists in the Dictionary)
Prefix ←Prefix + Char;
Else
{
Output : the code for Prefix;
insertInDictionary( (CodeWord, Prefix + Char) ) ;
CodeWord++;
Prefix←Char;
}
}
12. LZW Decoding:
The LZW decompressor creates the same string table during
decompression.
Initialize Dictionary with 256 ASCII codes and corresponding
single character strings as their translations.
13. LZW Decoding algorithm:
output: string(firstCodeWord);
while(there are more CodeWords)
{
If(Current code word is in the dictionary)
Output: String(Current Code Word);
Else
Ouput: PreviousOutput+Previous Output First character;
Insert in the dictionary: Previous output+ current output First
character.
}
16. Advantages :
This is a lossless compression technique, none of the contents
in the file are lost during or after compression.
LZW algorithm is efficient because it does not need to pass the
string table to the decompression code.
The table can be recreated as it was during compression, using
the input stream as data. This avoids insertion of large string
translation table with the compression data.
17. Disadvantages:
What happens when the dictionary becomes too large?
One approach is to throw the dictionary away when it reaches
a certain size.
Useful only for large amount of text data when redundancy is
high.
18. Applications:
A large English text file can typically be compressed via LZW
to about half its original size.
LZW became very widely used when it became part of
the GIF image format in 1987. It may also (optionally) be used
in TIFF and PDF files.