๐ Run-Length Coding (RLE)
B.Sc. Computer Science Honours – Data Compression
๐ 1. Introduction to Run-Length Coding
Run-Length Coding (RLC), commonly called Run-Length Encoding (RLE), is a simple lossless data compression technique.
The basic idea is to replace a sequence of consecutive identical symbols by a single symbol together with the number of times that symbol occurs consecutively.
Original:
Instead of storing every repeated symbol individually, RLE stores the run length and the corresponding symbol.
⌨️ 2. Interactive Run-Length Encoder
AAAAAABBBBCCCCC
AAABCCCCDDDDDD
111111100001111
๐ฏ 3. Encoded Output
๐ 4. Step-by-Step Encoding
๐ 5. Compression Statistics
๐ 6. Detailed Theory for B.Sc. Computer Science Honours
6.1 What is a Run?
A run is a consecutive sequence of identical symbols.
For example:
contains the following runs:
BBB → 3B
CCCCCC → 6C
DD → 2D
Therefore, the RLE representation is:
6.2 Basic Principle
Suppose a data sequence contains:
Instead of storing every character separately, RLE stores:
The two important components are:
- Run length: Number of consecutive occurrences.
- Symbol: The repeated character or data value.
6.3 Mathematical Representation
A sequence can be represented as:
If several consecutive symbols are identical:
then they can be represented by:
where k + 1 is the run length and sแตข is the repeated symbol.
6.4 RLE Encoding Algorithm
- Read the input sequence from left to right.
- Take the first symbol as the current symbol.
- Initialize the run count to 1.
- Compare the next symbol with the current symbol.
- If they are equal, increase the count.
- If they are different, output the count and current symbol.
- Make the new symbol the current symbol.
- Reset the count to 1.
- Continue until the end of the input.
- Output the final run.
6.5 RLE Decoding
Decoding reverses the encoding process.
For example:
is decoded as:
The decoder reads the run length and repeats the corresponding symbol that many times.
6.6 Time Complexity
For an input containing n symbols, a simple RLE encoder examines each symbol once.
The basic algorithm therefore has linear time complexity.
The additional working space is generally:
excluding the space required to store the encoded output.
6.7 When Does RLE Work Well?
RLE is particularly effective when the input contains long runs of identical values.
For example:
can be represented compactly as:
This produces a significant reduction in the amount of data.
6.8 When Does RLE Perform Poorly?
If consecutive symbols rarely repeat, RLE may provide little or no compression and can even increase the data size.
For example:
could become:
The encoded representation is clearly longer than the original.
6.9 RLE for Binary Images
Run-Length Coding is commonly explained using binary images. Consider one row of pixels:
This can be represented as:
This is useful because image regions often contain long sequences of the same pixel value.
6.10 RLE and Bitmap Images
RLE can be useful for simple images containing large areas of the same colour or intensity.
For example, a monochrome image containing large white backgrounds and black regions can contain long sequences of identical pixel values. These sequences can be represented using run lengths.
6.11 RLE in Data Compression Systems
RLE can be used as a standalone compression method or as one stage of a larger compression pipeline.
It may be combined with other techniques such as:
- Huffman coding
- Arithmetic coding
- Dictionary-based compression
- Entropy coding
6.12 Advantages of Run-Length Coding
- Very simple to understand and implement.
- Linear-time encoding.
- Linear-time decoding.
- Lossless compression.
- Requires relatively little computational processing.
- Effective for data containing long repeated sequences.
- Useful for simple bitmap and binary data.
6.13 Limitations of Run-Length Coding
- Not effective for highly random data.
- May increase the size of data with few repetitions.
- Compression ratio depends strongly on the input characteristics.
- Very short runs may create considerable overhead.
- It does not exploit complex statistical relationships between symbols.
6.14 RLE vs Arithmetic Coding
| Feature | Run-Length Coding | Arithmetic Coding |
|---|---|---|
| Basic idea | Represents repeated symbols using counts. | Represents a sequence using a fractional interval. |
| Primary requirement | Repeated consecutive symbols. | Probability model. |
| Complexity | Simple. | More mathematically involved. |
| Best suited for | Data containing long runs. | Data with useful statistical probability models. |
| Type | Lossless. | Lossless. |
6.15 Compression Ratio
A simple compression ratio can be calculated as:
For example, if the original representation requires 100 units and the compressed representation requires 50 units:
A larger ratio indicates greater reduction in representation size, although the actual storage cost of counts, delimiters and symbol representations must be considered in a real implementation.
6.16 Important Examination Points
- RLE stands for Run-Length Encoding.
- It is a lossless compression technique.
- A run consists of consecutive identical symbols.
- The run is represented using a count and symbol.
- Encoding and decoding are computationally simple.
- Basic encoding has O(n) time complexity.
- RLE performs well when long repeated runs exist.
- RLE may increase the size of data containing many unique consecutive symbols.
- It is useful in some bitmap, binary and structured data compression applications.
๐ง 7. Concept Summary
Example:
Thus, Run-Length Coding reduces redundancy by representing consecutive identical symbols using their run length and symbol.
No comments:
Post a Comment