Computer Science – 1.3 Compression | e-Consult
1.3 Compression (1 questions)
Run-Length Encoding (RLE) is a simple lossless compression technique that works by replacing consecutive sequences of the same character with a single instance of the character and a count of the repetitions. For example, the string "AAAAABBBCC" can be compressed to "5A3B2C".
Example: Consider a simple black and white image represented as a bitmap. If a large area of the image is black, it can be represented as a long sequence of '0's. RLE would compress this by storing the number of consecutive '0's and then the '0' itself. For instance, a row of 10 consecutive black pixels could be compressed as "100".
Limitations of RLE for images: RLE is inefficient for images with sparse data (i.e., images with few long runs of identical pixels). If an image has many different colors or patterns, the runs of identical pixels will be short, resulting in a larger compressed file than the original.
Alternative Compression Method: Huffman coding is a more suitable compression method for bitmap images. Huffman coding assigns shorter codes to more frequent pixel values, resulting in a better compression ratio than RLE, especially for images with a relatively uniform distribution of colors. Other image compression techniques like JPEG (which uses DCT) are even more effective but are more complex to implement.