|
Part 1: Playing with the Pixels
by James Antonakos
Start
ý Imaging 101 ý RLE
Compressor Tool ý Adjusting
the X-Y Resolution ý Adjusting
the Z-Axis Resolution ý Simple
Image Operations ý Run-Length
Compression ý More to Come
ý Sources and PDF
RUN-LENGTH COMPRESSION
One of the simplest compression schemes
available for images is Run-Length Encoding (RLE). In this technique,
a single pixel value and a repeat count replace consecutive pixels
in a single row of the image that have the same value. Figure 4 shows
a simple example.
 |
| Figure 4ýThe format of the
compressed RLE data is <repeat count>,<pixel value>.
In this example, 20 bytes of pixel data are reduced to 12 bytes
of RLE data, a compression of almost 50%. |
The more the pixels stay the same, the
greater the compression. For example, if the entire 256-pixel row
of an image contains black pixels, the RLE data will consist of only
two bytes (repeat count and pixel value). Photo 8 shows the results
of RLE compressing the source image with the RLE Image Compressor.
 |
| Photo 8ýNotice that each line
of pixels compresses differently. |
Look at how well the rows at the top
of the image have compressed compared to many of the rows making up
the face and shirt. The long runs of black pixels in the top rows
compress significantly. The rows of pixels making up the face and
shirt have many intensity variations and thus do not compress as well.
To RLE compress the source image, left-click
the Compress button. The processed image will be generated and the
compression ratio computed. The ratio for the processed image in Photo
8 is 0.63, meaning the compressed image is 63% of its original size.
Select five or fewer bits per pixel,
left-click Adjust Z to display the new processed image, and
then click Compress to see the compression results. You will see that
the compression ratio increases dramatically as fewer bits are used
to represent a pixel. Table 2 shows all the compression results for
the same source image. Note the last entry in the table. When using
a single bit per pixel, the RLE compressed image only requires 3%
of the original storage space. This is a nice feature of binary images.
|
Bits per pixel
|
Compression
|
|
6
|
0.63
|
|
5
|
0.46
|
|
4
|
0.30
|
|
3
|
0.17
|
|
2
|
0.09
|
|
1
|
0.03
|
|
Table 2ýAs fewer
bits are used to represent each pixel, the run-length compression
increases dramatically. Note that using five bits per pixel
results in almost the same image quality as six bits per pixel,
but at less than half (0.46) the storage requirements.
|
Expanding the RLE data into the original
image data is a simple matter of reading each <repeat count>,<pixel
value> pair and repeating the pixel the appropriate number of times.
RLE compression is lossless, meaning
that the expanded image data is exactly the same as the original image.
RLE compression is used in the PCX image file format. There are many
other compression methods, such as Huffman coding, LZW, and DCT. High-quality,
color JPG image files are compressed using DCT, and the subsequent
quantization of the coefficients makes it a lossy compression method.
The uncompressed image is slightly different than the original, with
little loss in quality. Lossy compression generally results in better
compression than lossless compression.
PREVIOUS
NEXT
Circuit Cellar provides up-to-date information for engineers. Visit
www.circuitcellar.com for
more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com
or subscribe online.
ýCircuit Cellar, the Magazine for Computer Applications. Posted with
permission. |