0% found this document useful (0 votes)
150 views2 pages

5-LZW Coding

LZW coding is an error-free compression technique that exploits repeating patterns in pixel values to reduce file size. It assigns variable-length code words to sequences of pixels without needing prior probability distributions. As the encoder examines pixels sequentially, unmatched sequences are added to the dictionary and assigned the next code. The decoder simultaneously reconstructs the dictionary from the encoded data stream. For a 4x4 test image, LZW coding reduced the file size by over 30% by identifying repeating sequences like lines of the same pixel value.

Uploaded by

vits knr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
150 views2 pages

5-LZW Coding

LZW coding is an error-free compression technique that exploits repeating patterns in pixel values to reduce file size. It assigns variable-length code words to sequences of pixels without needing prior probability distributions. As the encoder examines pixels sequentially, unmatched sequences are added to the dictionary and assigned the next code. The decoder simultaneously reconstructs the dictionary from the encoded data stream. For a 4x4 test image, LZW coding reduced the file size by over 30% by identifying repeating sequences like lines of the same pixel value.

Uploaded by

vits knr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Department of ECE

LZW Coding:
LZW coding is one of the several error free compression techniques that also attack an image inter pixel
redundancies.
 Lempel-Ziv-Welch (LZW) coding, assigns fixed-length code words to variable length sequences of
source symbols but requires no a priori knowledge of the probability of occurrence of the symbols to be
encoded.
 LZW compression has been integrated into a variety of mainstream imaging file formats, including the
graphic interchange format (GIF), tagged image file format (TIFF), and the portable document format
(PDF).
 At the onset of the coding process, a codebook or "dictionary" containing the source symbols to be coded
is constructed.
 For 8-bit monochrome images, the first 256 words of the dictionary are assigned to the gray values 0, 1,
2..., and 255.
 As the encoder sequentially examines the image's pixels, gray level sequences that are not in the
dictionary are placed in algorithmically determined (e.g., the next unused) locations.
 If the first two pixels of the image are white, for instance, sequence “255- 255” might be assigned to
location 256, the address following the locations reserved for gray levels 0 through 255. The next time
that two consecutive white pixels are encountered, code word 256, the address of the location containing
sequence 255-255, is used to represent them. If a 9-bit, 512-word dictionary is employed in the coding
process, the original (8 + 8) bits that were used to represent the two pixels are replaced by a single 9-bit
code word. Cleary, the size of the dictionary is an important system parameter. If it is too small, the
detection of matching gray level sequences will be less likely; if it is too large, the size of the code words
will adversely affect compression performance.

Consider the following 4 x 4, 8-bit image of a vertical edge:

39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126

Table 6.1 details the steps involved in coding its 16 pixels. A 512-word dictionary with the following starting
content is assumed:
Dictionary Location Entry
0 0
1 1
. .
. .
. .
255 255
256 ---
. .
. .
. .
511 ---

Locations 256 through 511 are initially unused. The image is encoded by processing its pixels in a left-to-
right, top-to-bottom manner. Each successive gray-level value is concatenated with a variable—column 1 of
Table 6.1 —called the "currently recognized sequence." As can be seen, this variable is initially null or empty.
The dictionary is searched for each concatenated sequence and if found, as was the case in the first row of the
table, is replaced by the newly concatenated and recognized (i.e., located in the dictionary) sequence. This
was done in column 1 of row 2.

Digital Image Processing Page 1


Department of ECE

Currently Dictionary
Pixel Being Encoded Dictionary
Recognized Location
Processed Output Entry
Sequence (Code Word)
39
39 39 39 256 39-39
39 126 39 257 39-126
126 126 126 258 126-126
39 39
39-39 126 256 260 39-39-126
126 126
126-126 39 258 261 126-126-39
39 39
39-39-126 126 260 262 39-39-126-126
126 39
126-39 39 259 263 126-39-39
39 126
39-126 126 257 264 39-126-126
126 126

Table 6.1 LZW coding example

No output codes are generated, nor are the dictionary altered. If the concatenated sequence is not found,
however, the address of the currently recognized sequence is output as the next encoded value, the
concatenated but unrecognized sequence is added to the dictionary, and the currently recognized sequence is
initialized to the current pixel value. This occurred in row 2 of the table. The last two columns detail the gray-
level sequences that are added to the dictionary when scanning the entire 4 x 4 image. Nine additional code
words are defined. At the conclusion of coding, the dictionary contains 265 code words and the LZW
algorithm has successfully identified several repeating gray-level sequences—leveraging them to reduce the
original 128-bit image lo 90 bits (i.e., 10 9-bit codes). The encoded output is obtained by reading the third
column from top to bottom. The resulting compression ratio is 1.42:1.
A unique feature of the LZW coding just demonstrated is that the coding dictionary or code book is
created while the data are being encoded. Remarkably, an LZW decoder builds an identical decompression
dictionary as it decodes simultaneously the encoded data stream. . Although not needed in this example, most
practical applications require a strategy for handling dictionary overflow. A simple solution is to flush or
reinitialize the dictionary when it becomes full and continue coding with a new initialized dictionary. A more
complex option is to monitor compression performance and flush the dictionary when it becomes poor or
unacceptable. Alternately, the least used dictionary entries can be tracked and replaced when necessary.

Digital Image Processing Page 2

You might also like