Total Pageviews

Wednesday, December 2, 2026

TWO DIMENSIONAL RUN LENGTH ENCODING(RAC METHOD)

RELATIVE ADDRESS CODING (RAC)

Two-Dimensional Run-Length Coding

Digital Image Processing | Binary Image Compression

1. Introduction

Relative Address Coding (RAC) is a two-dimensional run-length coding technique used for binary image compression. It is based on tracking the binary transitions that begin and end each black and white run.

In ordinary one-dimensional RLE, we encode consecutive identical pixel values by storing their values and run lengths. In RAC, the transition positions in the current row are encoded by comparing them with corresponding transitions in the previous row.

This use of information from the previous row makes RAC a two-dimensional coding approach.

RAC = Coding binary transition positions using relative distances
Main concept: Instead of independently encoding every run length, RAC uses the spatial relationship between transitions in two consecutive rows.

2. Why is RAC Required?

Consider a binary image containing text, diagrams or large black-and-white regions. The positions of transitions in neighbouring rows may be similar.

If the current row has a transition close to a similar transition in the previous row, it may be more efficient to encode the relative distance rather than its absolute position.

Previous row

Contains already processed binary transitions.

Current row

Contains the transitions that are being encoded.

Relative distance

Measures the relationship between transitions in the two rows.

RAC is particularly useful when binary patterns in neighbouring rows have related transition positions.

3. Understanding the Symbols in Figure 8.17

SymbolMeaning
cCurrent transition in the current row.
eLast transition of the current row.
c′First similar transition beyond e, in the previous row.
ecDistance from e to c.
cc′Distance from c to c′.
dDistance selected for RAC coding.

Visual understanding

Previous row

000111001100

Current row

001110011000

Illustrative binary rows only; the actual positions of transitions must be identified from the image.

A transition occurs when the binary pixel value changes from 0 to 1 or from 1 to 0.

4. Important Distance Calculations

According to Gonzalez and Woods, two distances are considered for the current transition c.

A. Distance ec

ec is the distance from the current transition c to the last transition e of the current line.

ec = Distance between e and c

B. Distance cc′

cc′ is the distance from c to the first similar transition beyond e, denoted by c′, in the previous line.

cc′ = Distance between c and c′

C. Selection of RAC distance

The smaller of the two distances is selected.

d = min(ec, cc′)

There are two cases:

Case 1

ec ≤ cc′

Select d = ec. The current-line distance is encoded.

Case 2

cc′ < ec

Select d = cc′. The direction of c′ (left or right) is also encoded.

5. RAC Coding Table – Figure 8.17

The following table reproduces the coding structure shown in the textbook screenshot.

Distance measuredDistanceCode
cc′00
ec or cc′ (left)1100
cc′ (right)1101
ecd (d > 1)111 h(d)
cc′ (c′ to left)d (d > 1)1100 h(d)
cc′ (c′ to right)d (d > 1)1101 h(d)
Remember: For d = 0, the code is 0. For d = 1, the code depends on whether the distance is ec, cc′ to the left, or cc′ to the right.

6. Understanding the Variable-Length Code h(d)

For distances greater than 1, RAC uses a variable-length code h(d). The distance is first placed into a range. A prefix identifies the range, and the remaining bits represent the offset within that range.

Distance rangePrefixOffset bitsh(d)
1 – 4020 XX
5 – 2010410 XXXX
21 – 841106110 XXXXXX
85 – 340111081110 XXXXXXXX
341 – 1364111101011110 XXXXXXXXXX
1365 – 546011111012111110 XXXXXXXXXXXX

How to calculate h(d)

For each range, subtract the first value of that range to obtain the offset. Convert the offset into binary using the specified number of bits, then attach the range prefix.

h(d) = Range prefix + Binary offset
RangeOffset calculationOffset width
1–4d − 12 bits
5–20d − 54 bits
21–84d − 216 bits
85–340d − 858 bits
341–1364d − 34110 bits
1365–5460d − 136512 bits
The h(d) range representation is used for d greater than 1 in the RAC cases above. The special cases d = 0 and d = 1 have their own codes.

7. Numerical Example 1 – From the Textbook Principle

Suppose the measured distances are:

ec = 8
cc′ = 4

Assume c′ is located to the left of c.

Step 1: Compare the distances

ec = 8,   cc′ = 4

Step 2: Select the smaller distance

d = min(8,4) = 4

Since cc′ is smaller than ec, the relative distance to c′ is selected.

Step 3: Determine the direction

c′ is to the left of c. Therefore, the appropriate code prefix is:

1100

Step 4: Calculate h(4)

Distance 4 belongs to the range 1–4.

Offset = d − 1 = 4 − 1 = 3

Convert 3 into a 2-bit binary number:

3 = (11)₂

Range prefix for 1–4 is 0.

h(4) = 0 + 11 = 011

Step 5: Generate the final RAC code

RAC code = 1100 + 011
1100011
Final answer: RAC code = 1100011. This is the example reported in the accompanying lecture material for ec = 8, cc′ = 4, with c′ to the left.

8. Numerical Example 2 – Current-Line Distance Selected

Suppose:

ec = 3,   cc′ = 7

Step 1: Select the smaller distance

d = min(3,7) = 3

Since ec is smaller, the current-line distance is selected.

Step 2: Find h(3)

Distance 3 belongs to range 1–4.

Offset = 3 − 1 = 2
2 in 2-bit binary = 10
h(3) = 0 + 10 = 010

Step 3: Apply the ec code prefix

RAC code = 111 + h(3)
111010

Final RAC code = 111010.

9. Numerical Example 3 – Right Direction

Suppose:

ec = 12,   cc′ = 6

Assume c′ is to the right of c.

Step 1: Select the smaller distance

d = min(12,6) = 6

Step 2: Calculate h(6)

6 belongs to the range 5–20.

Offset = 6 − 5 = 1
1 in 4-bit binary = 0001
h(6) = 10 + 0001 = 100001

Step 3: Apply the right-direction prefix

RAC code = 1101 + 100001
1101100001

Final RAC code = 1101100001.

10. Special Cases: d = 0 and d = 1

ConditionMeaningRAC code
cc′ = 0c is directly below the similar transition c′.0
ec = 1Current-line distance is one.100
cc′ = 1, c′ leftSimilar previous-row transition is one position to the left.100
cc′ = 1, c′ rightSimilar previous-row transition is one position to the right.101
When d = 1, the code identifies the measured-distance case. The encoder/decoder must follow the transition-position convention in the RAC scheme.

11. RAC Encoding Procedure

  1. Take the binary image and process it row by row.
  2. Use the previous row as the reference row.
  3. Identify the binary transitions in the current row.
  4. For the current transition c, determine the last transition e in the current row.
  5. Find the first similar transition c′ beyond e in the previous row.
  6. Calculate ec and cc′.
  7. Compare the two distances and select the smaller distance d.
  8. If d = 0 or d = 1, use the appropriate special code.
  9. If d is greater than 1, calculate h(d).
  10. Use the prefix for ec, cc′ left, or cc′ right.
  11. Repeat for the required transitions and rows.

Algorithm – Pseudocode

Algorithm RAC_Encode

For each current image row:

    Select the previous row as reference.

    Identify binary transitions in current row.

    For each current transition c:

        Find the last transition e
        in the current row.

        Find the first similar transition c'
        beyond e in the previous row.

        Calculate:
            ec = distance(e, c)
            cc' = distance(c, c')

        If ec <= cc':
            d = ec

            If d = 0:
                output special code 0

            Else if d = 1:
                output special code 100

            Else:
                output 111 + h(d)

        Else:
            d = cc'

            If d = 1 and c' is left:
                output 100

            Else if d = 1 and c' is right:
                output 101

            Else if d > 1 and c' is left:
                output 1100 + h(d)

            Else if d > 1 and c' is right:
                output 1101 + h(d)

Continue until all required transitions
have been encoded.

This is a teaching outline of the decision rules in Figure 8.17, not a complete standards-compliant RAC file encoder. Full image encoding also requires precise transition-search, row-boundary and initialization conventions.

12. Interactive RAC Code Calculator

Enter the two distances and choose the direction of c′. The calculator selects d, calculates h(d), and generates the RAC code according to the textbook table.

Enter the distances and click Calculate RAC Code.

13. Advantages of RAC

  • Uses information from two consecutive image rows.
  • Exploits similarity between transition positions in neighbouring rows.
  • Uses variable-length codes for representing distances.
  • Can reduce the number of bits needed for suitable binary images.
  • Useful for images containing structured black-and-white patterns.
  • Encodes spatial relationships between transitions.

14. Disadvantages of RAC

  • More complex than simple one-dimensional RLE.
  • Requires transition detection and reference-row information.
  • Encoding and decoding require careful tracking of positions.
  • Compression efficiency depends on the relationship between neighbouring rows.
  • Less suitable for images without useful binary transition patterns.
  • Requires correct handling of image boundaries and initial reference rows.

15. RLE vs RAC

FeatureOrdinary RLERelative Address Coding
DimensionUsually one-dimensional scanTwo-dimensional row-based coding
Basic informationPixel value and run lengthRelative positions of binary transitions
Previous rowNot normally requiredUsed as reference
Distance codingRun countec and cc′ distances
Code structureValue-count pairsSpecial prefixes and h(d)
ComplexitySimpleMore complex

16. Important Examination Questions

  1. What is Relative Address Coding?
  2. Explain the principle of two-dimensional run-length coding.
  3. Define ec and cc′ in RAC.
  4. Explain the selection rule d = min(ec, cc′).
  5. Write the RAC coding table given in Figure 8.17.
  6. What is the purpose of h(d)?
  7. Explain the variable-length distance ranges used in RAC.
  8. Calculate the RAC code when ec = 8, cc′ = 4 and c′ is to the left.
  9. Explain the special coding cases for d = 0 and d = 1.
  10. Differentiate between ordinary RLE and RAC.

17. Conclusion

Relative Address Coding is a two-dimensional extension of run-length coding. It tracks binary transitions in the current row and compares their positions with similar transitions in the previous row. By selecting the smaller of ec and cc′ and representing the selected distance with special prefixes and h(d), RAC can exploit similarities between neighbouring rows of a binary image.

18. References

  1. Rafael C. Gonzalez and Richard E. Woods, Digital Image Processing, 2nd Edition, Chapter 8 – Image Compression, Two-Dimensional Run-Length Coding, Figure 8.17.
  2. Gonzalez and Woods – Chapter 8, Figure 8.17: Relative Address Coding
  3. Digital Image Processing – 1-D and 2-D Run-Length Coding lecture material

The coding table and distance definitions follow the supplied textbook screenshot. Numerical examples are educational calculations based on that table.

19. Interactive RAC Calculator – Point Input and Step-by-Step Output

Enter the horizontal positions of the three transition points. The calculator will automatically calculate the distances and generate the RAC code.

Coordinate convention: All three positions are horizontal pixel positions measured from the same left-hand reference. Point e and point c belong to the current row. Point c′ belongs to the previous row.

Point e

Last transition in the current row.

Point c

Current transition in the current row.

Point c′

Similar transition in the previous row.

Waiting for point input...

Enter e, c and c′, then click Generate RAC Output.

Try this example: e = 10, c = 18, c′ = 14.

Expected distances: ec = 8 and cc′ = 4.

Since cc′ is smaller and c′ is to the left, the final RAC code is 1100011.

Run Length Encoding (RLE)

RUN LENGTH ENCODING (RLE)

Digital Image Processing – Image Compression Technique

Lossless Compression | Spatial Redundancy Reduction

RLEImage CompressionWoods Chapter 8

1. Introduction

Run Length Encoding (RLE) is a simple lossless data compression technique. It reduces the size of data by replacing consecutive occurrences of the same symbol or pixel intensity with a pair containing the symbol and the number of times it is repeated.

A sequence of repeated pixel values is called a run. Instead of storing every pixel separately, RLE stores the pixel value and its run length.

RLE pair = (Pixel value, Run length)

Example:

AAAAABBBBCCCCC

RLE representation:

(A,5), (B,4), (C,5)
RLE does not discard image information. The original sequence can be reconstructed exactly from the encoded run-length pairs.

2. Why is RLE used in Digital Image Processing?

Many digital images contain large areas of the same or similar intensity values. For example, a binary image may contain long sequences of black pixels followed by long sequences of white pixels.

Storing every pixel individually requires more data. RLE represents consecutive identical pixels compactly.

Without RLE

0, 0, 0, 0, 0, 0, 1, 1, 1, 1

Ten individual pixel values are stored.

With RLE

(0,6), (1,4)

Only two run-length pairs are stored.

RLE is particularly useful for binary images, scanned documents, diagrams, icons, and images with large uniform regions.

3. Basic Working Principle

The encoder scans the image data in a predefined order, usually from left to right along each row. It counts consecutive pixels having the same intensity.

Step 1: Read

Read the first pixel.

Step 2: Compare

Compare the next pixel with the current pixel.

Step 3: Count

If both are equal, increase the run count.

Step 4: Encode

If the value changes, output the previous value and its count.

Step 5: Continue

Start a new run and continue scanning.

Step 6: Finish

Output the final run.

General example:

Input: A A A A B B C C C D D
Output: (A,4), (B,2), (C,3), (D,2)

4. Mathematical Representation

Let the input pixel sequence be:

X = {x₁, x₂, x₃, ..., xₙ}

For each consecutive group of identical values, RLE produces a pair:

(vᵢ, rᵢ)
  • vᵢ = pixel intensity or symbol value.
  • rᵢ = number of consecutive occurrences.
  • n = total number of input pixels.
  • k = total number of runs.
n = r₁ + r₂ + r₃ + ... + rₖ

For a valid sequence, each run has a positive length and adjacent runs have different values.

Compression Ratio

Compression Ratio (CR) = Original data size / Compressed data size

If CR is greater than 1, compression is achieved. If it is less than 1, the encoded data is larger than the original.

5. Step-by-Step Numerical Example – 1

Consider the following pixel sequence:

5, 5, 5, 5, 2, 2, 8, 8, 8, 1

Step 1: Start with the first pixel, 5.

Step 2: Count consecutive occurrences of 5. There are four occurrences.

Step 3: The next value is 2. Therefore, finish the first run.

Step 4: Count the two occurrences of 2.

Step 5: Count the three occurrences of 8.

Step 6: The final value 1 occurs once.

Pixel valueRun lengthEncoded pair
54(5,4)
22(2,2)
83(8,3)
11(1,1)
Encoded output = (5,4), (2,2), (8,3), (1,1)

Original sequence contains 10 pixel values. The RLE output contains 4 pairs.

For illustration, if every original pixel requires 8 bits and every encoded pair uses 8 bits for the pixel value plus 8 bits for the count, the original requires 80 bits and the encoded sequence requires 64 bits.
CR = 80 / 64 = 1.25

This example assumes an 8-bit count field and excludes file headers and other storage overhead.

6. Step-by-Step Numerical Example – 2 (Binary Image)

Consider a single row of a binary image:

0 0 0 0 0 0 1 1 1 1 0 0 0 0

Here, 0 represents black and 1 represents white.

Run numberPixel valueNumber of pixels
10 (Black)6
21 (White)4
30 (Black)4
RLE = (0,6), (1,4), (0,4)

For binary images, an alternative representation stores only run lengths if the first pixel value and the alternating black/white convention are known.

The decoder must know the starting pixel value and the scan-line convention. Otherwise, run lengths alone are ambiguous.

7. RLE Applied to a 2D Image

Consider a small grayscale image containing three rows:

000255255
00128128128
25525525500

Each row is encoded independently.

RowOriginal pixelsRLE representation
10,0,0,255,255(0,3), (255,2)
20,0,128,128,128(0,2), (128,3)
3255,255,255,0,0(255,3), (0,2)

Important: In two-dimensional image coding, row boundaries must be preserved. A run should not accidentally continue from the end of one row into the beginning of the next row unless the format explicitly defines a continuous scan.

8. RLE Encoding Algorithm

Pseudocode

Algorithm RLE_Encode(input)

1. Initialize an empty output list.
2. Set i = 0.
3. While i is less than the length of input:
      value = input[i]
      count = 1

      While the next element exists
      and input[i + count] = value:
          count = count + 1

      Add (value, count) to output.
      i = i + count

4. Return output.

Python Implementation

def rle_encode(data):
    if not data:
        return []

    encoded = []
    current = data[0]
    count = 1

    for value in data[1:]:
        if value == current:
            count += 1
        else:
            encoded.append((current, count))
            current = value
            count = 1

    encoded.append((current, count))
    return encoded


pixels = [5, 5, 5, 5, 2, 2, 8, 8, 8, 1]

result = rle_encode(pixels)

print("Original:", pixels)
print("Encoded:", result)

Expected output:

Original: [5, 5, 5, 5, 2, 2, 8, 8, 8, 1]
Encoded: [(5, 4), (2, 2), (8, 3), (1, 1)]

9. RLE Decoding Algorithm

The decoder reads each pair and repeats the pixel value according to its run length.

Decoded data = Repeat(value, run length)

Pseudocode

Algorithm RLE_Decode(encoded)

1. Initialize an empty output list.
2. For each pair (value, count):
      Repeat count times:
          Add value to output.
3. Return output.

Python Implementation

def rle_decode(encoded):
    decoded = []

    for value, count in encoded:
        decoded.extend([value] * count)

    return decoded


encoded = [(5, 4), (2, 2), (8, 3), (1, 1)]

original = rle_decode(encoded)

print("Decoded:", original)

Expected output:

Decoded: [5, 5, 5, 5, 2, 2, 8, 8, 8, 1]
RLE is a lossless method: the decoded sequence is identical to the original sequence when the encoded data and its format are preserved correctly.

10. Interactive RLE Encoder and Decoder

Enter pixel values separated by commas. The tool will encode the sequence into run-length pairs and decode it again.

Encoded and decoded results will appear here.

11. Applications of Run Length Encoding

1. Binary Images

Compression of black-and-white images containing large uniform regions.

2. Scanned Documents

Used in document images, text pages and fax-related image coding.

3. BMP Images

BMP supports RLE-based encoding modes for certain indexed and grayscale image formats.

4. Graphics and Icons

Useful for simple graphics with repeated colours or pixel values.

5. Image Compression Standards

Run-length techniques or run-length representations are used in different compression systems and coding stages.

6. Data Storage

Useful for repetitive sequences in certain structured data.

12. Advantages of RLE

  • Simple and easy to implement.
  • Lossless compression technique.
  • Fast encoding and decoding.
  • Requires relatively little computational power.
  • Effective for images with long runs of identical pixel values.
  • Suitable for binary images and simple graphics.
  • Original data can be reconstructed exactly.

13. Disadvantages of RLE

  • Not suitable for photographs containing frequent pixel variations.
  • May increase the size of data when runs are very short.
  • Compression efficiency depends on the distribution of repeated values.
  • Run-length counts require additional storage.
  • Encoding format must preserve row boundaries and run conventions.
  • Long runs may require special handling if the count field has a limited range.

14. Complexity Analysis

OperationTime complexityExplanation
EncodingO(n)Every input element is scanned once.
DecodingO(n)Every reconstructed output element is generated once.
Auxiliary spaceO(k)Encoded output contains k run pairs.

Here, n is the number of input pixels and k is the number of runs. The decoded output itself requires O(n) space when stored in memory.

15. RLE vs Other Compression Techniques

FeatureRLEHuffman CodingLZW
Basic ideaStore repeated values as runsVariable-length codes based on frequencyDictionary-based sequence coding
LosslessYesYesYes
Best suited forLong repeated sequencesUnequal symbol frequenciesRepeated patterns and sequences
ImplementationSimpleModerateModerate
WeaknessShort runs may expand dataNeeds code constructionDictionary management

16. Important Examination Questions

  1. Define Run Length Encoding.
  2. Explain the working principle of RLE with an example.
  3. Write the encoding and decoding algorithms of RLE.
  4. Explain how RLE is used in binary image compression.
  5. Calculate the RLE representation of a given pixel sequence.
  6. Discuss the advantages and disadvantages of RLE.
  7. Why is RLE suitable for images containing large uniform regions?
  8. Explain why RLE may increase the size of some images.
  9. Differentiate between RLE, Huffman coding and LZW coding.
  10. Discuss the time complexity of RLE encoding and decoding.

17. Conclusion

Run Length Encoding is a simple and effective lossless image compression method when an image contains consecutive identical pixel values. It reduces spatial redundancy by replacing repeated pixels with run-length pairs. Its performance depends on the number and length of runs in the image. It is particularly useful for binary images, scanned documents and simple graphics, but is less effective for complex natural photographs.

18. References

  1. Rafael C. Gonzalez and Richard E. Woods, Digital Image Processing, 3rd Edition, Chapter 8 – Image Compression, Section 8.2.5 – Run-Length Coding.
  2. Rafael C. Gonzalez and Richard E. Woods, Digital Image Processing, 4th Edition, Chapter 8 – Image Compression and Watermarking, Section 8.6 – Run-Length Coding.
  3. Gonzalez and Woods – Digital Image Processing, 4th Edition (reference PDF)
  4. Khan Academy – Lossless Image Compression

The numerical examples and interactive demonstration on this page are educational illustrations of the RLE principle.

ENCODER - DECODER MODEL

IMAGE ENCODER AND DECODER MODEL

Image Compression and Reconstruction

Based on Digital Image Processing by Gonzalez and Woods

Image Compression Encoder Decoder Lossless and Lossy

1. Introduction

An Encoder and Decoder Model is an important concept in Digital Image Processing. It is used to reduce the amount of data required to represent an image and reconstruct the image when it is decoded.

A digital image contains a large amount of information. Image compression techniques reduce the data by removing different types of redundancy.

The encoder converts the original image into a compressed representation. The decoder uses the compressed information to reconstruct the image.

Original Image → Encoder → Compressed Data

Compressed Data → Decoder → Reconstructed Image

According to Gonzalez and Woods, a general image compression system consists of three major encoding operations:

  1. Mapper
  2. Quantizer
  3. Symbol Coder

The corresponding decoder contains:

  1. Symbol Decoder
  2. Inverse Mapper
Important: The quantizer is responsible for irreversible information loss in lossy compression. It is omitted in error-free or lossless compression.

2. General Image Compression Model

The general model described by Gonzalez and Woods can be represented as follows.

Encoder Model

Input Image
f(x,y)
→ Mapper → Quantizer → Symbol Coder → Compressed Data

Decoder Model

Compressed Data → Symbol Decoder → Inverse Mapper → Output Image
f̂(x,y)
The encoder removes redundancies and creates a compact representation. The decoder reconstructs the image using the encoded information.

3. Components of an Image Encoder

3.1 Mapper

The mapper converts the original image into a different representation to reduce spatial or interpixel redundancy.

It transforms the image into a format that is more suitable for compression.

Examples:

  • Run-Length Coding (RLC)
  • Differential Pulse Code Modulation (DPCM)
  • Discrete Cosine Transform (DCT)
  • Wavelet Transform
Original Image → Mapper → Transformed Representation
A mapper may be reversible. It can reorganize image data without necessarily reducing the number of bits immediately. For example, a transform can concentrate information into a smaller number of significant coefficients.

3.2 Quantizer

The quantizer reduces the precision of the mapped image values by assigning them to a limited set of representative levels.

It is used to remove psychovisual redundancy by reducing information that is less noticeable to the human visual system.

Example:

Original Value = 127
Quantized Value = 120

The difference between the original and quantized value is the quantization error.

e = Original Value - Quantized Value
e = 127 - 120 = 7
Quantization is generally irreversible. Once information is discarded during quantization, the decoder cannot recover the exact original value.

3.3 Symbol Coder

The symbol coder converts the quantized values into binary codewords for efficient storage or transmission.

It reduces coding redundancy by assigning shorter codewords to frequently occurring symbols.

Examples:

  • Huffman Coding
  • Arithmetic Coding
  • Variable-Length Coding
Quantized Symbols → Binary Codewords
Symbol coding is generally reversible. The original quantized symbols can be recovered from the coded data.

4. Components of an Image Decoder

4.1 Symbol Decoder

The symbol decoder converts the compressed binary codewords back into the corresponding quantized symbols.

It performs the reverse operation of the symbol coder.

Compressed Data → Symbol Decoder → Quantized Symbols

4.2 Inverse Mapper

The inverse mapper converts the decoded representation back into the spatial image domain.

It performs the reverse operation of the mapper. For transform-based compression, it applies the corresponding inverse transform.

Examples:

  • Inverse DCT
  • Inverse Wavelet Transform
  • Inverse Predictive Mapping
  • Reconstruction of image blocks
Decoded Representation → Inverse Mapper → Reconstructed Image
The reconstructed image is represented by f̂(x,y). In lossless compression, it is identical to the original image. In lossy compression, some differences may exist.

5. Channel Encoder and Channel Decoder

In an image transmission system, the compressed data may pass through a communication channel.

To protect the compressed data from transmission errors, additional channel coding can be applied.

Channel Encoder

Adds redundancy to the compressed bitstream to help detect or correct errors during transmission.

Channel

The medium through which the data is transmitted, such as a wireless network, optical fibre or storage link.

Channel Decoder

Uses the added redundancy to detect or correct transmission errors before the image compression decoder processes the compressed data.

Source Encoder → Channel Encoder → Communication Channel → Channel Decoder → Source Decoder
Remember: Source coding performs image compression. Channel coding provides protection against transmission errors. They have different purposes.

6. Lossless and Lossy Compression Models

6.1 Lossless Compression

In lossless compression, the reconstructed image is exactly the same as the original image.

f̂(x,y) = f(x,y)

The quantizer is omitted because no image information should be discarded.

Examples:

  • Huffman Coding
  • Run-Length Coding
  • LZW Coding
Original Image → Reversible Mapper → Symbol Coder → Compressed Data

6.2 Lossy Compression

In lossy compression, some information is discarded during quantization to achieve a higher compression ratio.

f̂(x,y) ≠ f(x,y)

Examples:

  • JPEG compression
  • Transform Coding with Quantization
  • Wavelet-based lossy compression
Original Image → Mapper → Quantizer → Symbol Coder

7. Step-by-Step Numerical Example

Consider a simple grayscale image represented by the following pixel values:

Step 1: Original Image

120125128135
140145150155

Step 2: Mapping Operation

For illustration, consider a simple mapping operation that calculates the difference between consecutive pixel values in a row.

d(i) = f(i) - f(i-1)

For the first row:

120, 125, 128, 135

Mapped Values:
120, 5, 3, 7

For the second row:

140, 145, 150, 155

Mapped Values:
140, 5, 5, 5
120537
140555

The differences are much smaller than many of the original pixel values. This can make subsequent compression more effective.

Step 3: Quantization

Assume a simple quantizer with step size Δ = 4. For this example, quantization is performed using:

q = round(d / 4)

Quantization calculations:

Mapped ValueCalculationQuantized Value
120round(120/4)30
5round(5/4)1
3round(3/4)1
7round(7/4)2
140round(140/4)35
5round(5/4)1
5round(5/4)1
5round(5/4)1

Step 4: Symbol Coding

The quantized symbols can now be represented using binary codewords.

SymbolExample Codeword
10
210
30110
35111

The resulting illustrative compressed bitstream is:

110 | 0 | 0 | 10 | 111 | 0 | 0 | 0
The codewords above are an illustrative prefix code for this small example, not the output of a complete Huffman coding procedure. A real encoder constructs its code according to symbol frequencies.

Step 5: Decoding

The decoder reverses the operations:

  1. Symbol decoder recovers the quantized values.
  2. Inverse quantizer multiplies the values by 4 to obtain reconstructed differences.
  3. Inverse mapper adds the differences cumulatively to reconstruct the pixels.

Step 6: Reconstructed Values

First row:

30 × 4 = 120
1 × 4 = 4
1 × 4 = 4
2 × 4 = 8

Reconstruction:
120, 124, 128, 136

Second row:

35 × 4 = 140
1 × 4 = 4
1 × 4 = 4
1 × 4 = 4

Reconstruction:
140, 144, 148, 152

Original vs Reconstructed Image

Original Reconstructed
120120
125124
128128
135136
140140
145144
150148
155152
The reconstructed image is not exactly equal to the original because quantization has introduced errors. This is an example of lossy image compression.

8. Encoder Algorithm

IMAGE_ENCODER(Original_Image):

1. Read the original image.

2. MAPPED_DATA = MAPPER(Original_Image)

3. QUANTIZED_DATA = QUANTIZER(MAPPED_DATA)

4. COMPRESSED_DATA =
   SYMBOL_ENCODER(QUANTIZED_DATA)

5. Store or transmit COMPRESSED_DATA.

6. END

Decoder Algorithm

IMAGE_DECODER(Compressed_Data):

1. Read compressed data.

2. DECODED_SYMBOLS =
   SYMBOL_DECODER(Compressed_Data)

3. RECONSTRUCTED_IMAGE =
   INVERSE_MAPPER(DECODED_SYMBOLS)

4. Display reconstructed image.

5. END
For lossy compression, the quantization levels must be taken into account during reconstruction. The decoder uses the representative values associated with those quantization levels.

9. Types of Redundancy Removed by Encoder

1. Coding Redundancy

Occurs when more bits are used than necessary to represent the information. Symbol coding reduces this redundancy.

2. Interpixel Redundancy

Neighbouring pixels often have similar intensity values. Mapping operations such as predictive coding help reduce this redundancy.

3. Psychovisual Redundancy

Some image information is less noticeable to human vision. Quantization can remove or reduce this information.

RedundancyOperation
Coding RedundancySymbol Coder
Interpixel RedundancyMapper
Psychovisual RedundancyQuantizer

10. Performance Measurement of Image Compression

Compression Ratio

CR = Original Data Size / Compressed Data Size

For example, if an image requires 800 KB and the compressed image requires 200 KB:

CR = 800 / 200 = 4 : 1

Mean Squared Error (MSE)

MSE = (1/MN) Σ Σ [f(x,y) - f̂(x,y)]²

MSE measures the average squared difference between the original and reconstructed image.

Peak Signal-to-Noise Ratio (PSNR)

PSNR = 10 log10 (MAX² / MSE)

For an 8-bit grayscale image, MAX = 255. A higher PSNR generally indicates lower reconstruction error.

For a perfectly reconstructed image, MSE = 0 and PSNR is theoretically infinite.

11. Advantages of Encoder and Decoder Model

  • Reduced Storage: Compressed images require less storage space.
  • Faster Transmission: Smaller data can be transmitted more efficiently.
  • Flexible Design: Different mapping and coding methods can be combined.
  • Lossless Support: The model can preserve the exact original image.
  • Lossy Support: It can achieve higher compression by controlling image quality.
  • Efficient Processing: Each stage performs a specific operation.
  • Wide Applications: Used in image storage, communication and multimedia systems.

12. Disadvantages of Encoder and Decoder Model

  • Computational Cost: Some transformations and coding operations require significant processing.
  • Quality Loss: Lossy quantization can introduce image distortion.
  • Complexity: Advanced compression methods require more complicated encoding and decoding.
  • Memory Requirements: Intermediate image representations may require additional memory.
  • Encoding Time: Complex coding methods may increase processing time.
  • Compatibility: Encoder and decoder must follow compatible compression formats and parameters.

13. Applications

  • JPEG image compression.
  • Digital photography and image storage.
  • Medical image archiving and transmission.
  • Satellite and remote sensing image transmission.
  • Web image optimization.
  • Video compression systems.
  • Digital multimedia communication.
  • Image databases and cloud storage.

14. Interactive Encoder and Decoder Demonstration

Enter grayscale pixel values and observe the operations of the encoder and decoder. This demonstration uses predictive mapping, scalar quantization and a simple illustrative symbol representation.

Step 1: Input Image Pixel Values

Enter eight grayscale values separated by commas.

Step 2: Select Compression Type

Step 3: Quantization Step Size

The results will appear here after running the model.

15. Conclusion

The Encoder and Decoder Model is the foundation of image compression in Digital Image Processing.

The encoder uses a mapper, quantizer and symbol coder to reduce the amount of data required to represent an image. The decoder uses symbol decoding and inverse mapping to reconstruct the image.

In lossless compression, the reconstructed image is identical to the original. In lossy compression, quantization reduces the data size at the expense of some image quality.

Understanding this model helps students understand JPEG, predictive coding, transform coding and other image compression techniques.

16. References and Study Materials

Primary Textbook:

Rafael C. Gonzalez and Richard E. Woods, Digital Image Processing, 3rd Edition, Prentice Hall, Chapter 8 – Image Compression.

📘 Reference 1: Gonzalez and Woods – Digital Image Processing, 3rd Edition 📗 Reference 2: Chapter 8 – General Image Compression Model 📙 Reference 3: Image Compression – Encoder and Decoder Block Diagram

Bit Plane Coding (Bit Plane Slicing)

BIT PLANE CODING

Bit Plane Slicing and Image Compression

Digital Image Processing

Image Decomposition Binary Images Image Compression

1. Introduction to Bit Plane Coding

Bit Plane Coding is a technique used in Digital Image Processing to reduce image data by separating an image into individual binary bit planes and processing each plane separately.

A digital grayscale image generally contains 8 bits per pixel. Therefore, each pixel can represent an intensity value from 0 to 255.

Each 8-bit pixel can be decomposed into eight individual 1-bit planes. Each plane represents one particular bit position of every pixel in the image.

The higher-order bit planes contain most of the visually significant image information, whereas the lower-order bit planes generally contain finer intensity variations and subtle details.

Important Concept: An 8-bit grayscale image can be divided into eight binary images. These binary images can then be compressed individually using suitable binary coding techniques.

Characteristics

  • It is based on binary representation of pixel values.
  • An 8-bit image produces eight bit planes.
  • Each bit plane is a binary image.
  • Higher-order planes generally contain more visual information.
  • Individual planes can be processed and compressed separately.

2. Basic Concept of Bit Plane Decomposition

Suppose a grayscale image has 8 bits per pixel. Every pixel intensity can be represented in binary form.

8-bit pixel = b7b6b5b4 b3b2b1b0

The eight bits are separated into eight different planes.

Bit Plane Bit Position Weight Description
Plane 7MSB128Highest significance
Plane 6Bit 664High significance
Plane 5Bit 532High significance
Plane 4Bit 416Medium significance
Plane 3Bit 38Lower significance
Plane 2Bit 24Lower significance
Plane 1Bit 12Low significance
Plane 0LSB1Lowest significance
MSB: Most Significant Bit (Bit 7).
LSB: Least Significant Bit (Bit 0).

3. Mathematical Representation

An image pixel intensity can be expressed using binary polynomial representation.

For an 8-bit pixel:

f(x,y) = b727 + b626 + b525 + b424 + b323 + b222 + b121 + b020

Where:

  • f(x,y) = Original pixel intensity.
  • bk = Binary value (0 or 1) at bit position k.
  • k = Bit position from 0 to 7.
  • 2k = Weight of the corresponding bit.

Bit Plane Extraction Formula

Bk(x,y) = ⌊ f(x,y) / 2k ⌋ MOD 2

This formula extracts the kth bit of a pixel. The result is always either 0 or 1.

Image Reconstruction Formula

f(x,y) = Σ Bk(x,y) × 2k
k = 0 to 7

The original pixel value is reconstructed by multiplying each bit plane by its corresponding weight and adding the results.

4. Numerical Example of Bit Plane Decomposition

Consider a pixel having intensity value:

f(x,y) = 220

Step 1: Convert Decimal to Binary

Divide the decimal number by 2 repeatedly and collect the remainders.

DivisionQuotientRemainder
220 ÷ 21100
110 ÷ 2550
55 ÷ 2271
27 ÷ 2131
13 ÷ 261
6 ÷ 230
3 ÷ 211
1 ÷ 201
220 = (11011100)2

Step 2: Identify Individual Bits

Bit Position Bit Value Weight Contribution
71128128
616464
50320
411616
3188
2144
1020
0010

Step 3: Calculate Original Intensity

220 = 128 + 64 + 16 + 8 + 4

Therefore, the pixel value is reconstructed from the eight individual bit values.

Step 4: Final Bit Plane Values

B7 = 1, B6 = 1, B5 = 0, B4 = 1
B3 = 1, B2 = 1, B1 = 0, B0 = 0

5. Bit Plane Decomposition of an Image Matrix

Consider the following 2 × 3 grayscale image matrix:

Original Image Matrix

22015075
45128255

Binary Representation

22015075
110111001001011001001011
45128255
001011011000000011111111

Bit Plane 7 (MSB)

110
011

Bit Plane 6

101
001

Bit Plane 5

000
101

Bit Plane 4

110
001

Bit Plane 3

101
101

Bit Plane 2

110
101

Bit Plane 1

011
001

Bit Plane 0 (LSB)

001
101
Each matrix represents one binary image. All eight matrices together contain the complete information of the original image.

6. Bit Plane Coding Algorithm

Encoding Algorithm

  1. Read the original grayscale image.
  2. Convert each pixel into its binary representation.
  3. Separate the binary representation into individual bit planes.
  4. Generate eight binary images for an 8-bit grayscale image.
  5. Process each binary image separately.
  6. Apply a suitable binary compression method, such as run-length coding or another binary coding technique.
  7. Store or transmit the compressed bit planes along with the necessary coding information.

Pseudocode for Bit Plane Encoding

BIT_PLANE_ENCODING(Image):

1. Read the input grayscale image.

2. FOR k = 0 TO 7:

      Create an empty binary plane.

      FOR every pixel (x,y):

          Bk(x,y) = floor(Image(x,y) / 2^k) MOD 2

      END FOR

      Compress the binary plane.

      Store the compressed plane.

3. END FOR

4. Store required image and coding information.

5. END

Decoding Algorithm

  1. Read the compressed bit-plane data.
  2. Decode each individual binary plane.
  3. Initialize the reconstructed image with zero values.
  4. Multiply each decoded plane by its corresponding bit weight.
  5. Add all weighted planes.
  6. Obtain the reconstructed grayscale image.

Pseudocode for Decoding

BIT_PLANE_DECODING():

1. Initialize reconstructed image = 0.

2. FOR k = 0 TO 7:

      Decode bit plane Bk.

      Reconstructed Image =
      Reconstructed Image + Bk * 2^k

3. END FOR

4. Display reconstructed image.

5. END

7. Bit Plane Coding Flowchart

Original Image ↓ Binary Conversion ↓ Bit Plane Decomposition ↓ Eight Binary Images ↓ Individual Compression ↓ Compressed Bit Planes

Reconstruction Flow

Compressed Data → Decode Planes → Apply Bit Weights → Add Planes → Reconstructed Image

8. Importance of Higher and Lower Bit Planes

Higher-Order Bit Planes

Bit planes 7, 6, 5 and 4 generally contain most of the visually significant information in a grayscale image. They contribute more heavily to the overall intensity and structure of the image.

Lower-Order Bit Planes

Bit planes 3, 2, 1 and 0 generally contain smaller intensity variations and subtle image details. The lowest bit plane contributes only 0 or 1 to the original pixel intensity.

Important: Lower-order planes are not always meaningless noise. They can contain important edges, textures or fine details. The actual information distribution depends on the image.

Reconstruction Using Selected Planes

Suppose we reconstruct an image using only the four highest-order planes (7, 6, 5 and 4).

Ireconstructed = 128B7 + 64B6 + 32B5 + 16B4

The reconstructed intensity is an approximation of the original image. The omitted lower-order planes contribute to the difference.

9. Applications of Bit Plane Coding

1. Digital Image Compression

The individual binary planes can be compressed separately to reduce the amount of data required for image storage.

2. Medical Image Processing

Bit-plane analysis can help study the contribution of different intensity bits in medical images.

3. Image Enhancement

Selected bit planes can be analyzed to understand important structures and intensity variations.

4. Image Analysis

Separating the bit planes helps study the significance of different binary components of image pixels.

5. Digital Watermarking

Selected bit planes, particularly lower-order planes, can be used in certain watermarking techniques.

6. Image Transmission

Bit-plane based progressive transmission can send important image information before less significant details.

10. Advantages of Bit Plane Coding

  • Separate Processing: Each binary plane can be processed independently.
  • Lossless Decomposition: Keeping all planes preserves the original pixel values exactly.
  • Information Analysis: Helps identify which bits contribute most to image appearance.
  • Flexible Compression: Different compression methods can be applied to different planes.
  • Progressive Reconstruction: Important planes can be transmitted first.
  • Reduced Data: Selected planes can be discarded when approximate reconstruction is acceptable.
  • Simple Mathematical Representation: Based on binary representation and powers of two.

11. Disadvantages of Bit Plane Coding

  • Multiple Planes: An 8-bit image produces eight separate binary images.
  • Processing Overhead: Every plane needs separate processing and management.
  • Variable Compression: Some binary planes may not compress effectively.
  • Loss of Information: Discarding planes causes loss of the corresponding pixel information.
  • Complexity: Additional coding and reconstruction procedures are required.
  • Image Dependency: Compression performance depends on the distribution of bits and spatial patterns.
  • Storage Overhead: Separate plane storage and metadata can add overhead.

12. Bit Plane Slicing vs Bit Plane Coding

Feature Bit Plane Slicing Bit Plane Coding
Meaning Separates an image into binary planes. Separates and compresses individual binary planes.
Main Purpose Image analysis and visualization. Image data compression.
Output Binary images. Compressed binary-plane data.
Compression Not necessarily performed. Compression is applied.
Reconstruction Combine all planes using weights. Decode planes and combine using weights.

13. Conclusion

Bit Plane Coding is an important technique in Digital Image Processing. It decomposes a multilevel image into a set of binary images and processes each plane individually.

The higher-order planes generally contain more visually significant information, while lower-order planes contribute to finer intensity details.

By compressing individual bit planes, it is possible to reduce image data and support progressive image transmission. It is also useful for image analysis and understanding the contribution of individual bits to the overall image.

14. Interactive Bit Plane Coding Tool

Upload a grayscale or colour image. This tool converts it to grayscale, extracts all eight bit planes and demonstrates image reconstruction using selected planes.

Instructions: Select an image from your computer. The tool will automatically display the original grayscale image and its eight individual bit planes.

Original Grayscale Image

Please upload an image.

Eight Individual Bit Planes

Image Reconstruction

Select the number of highest-order bit planes to use for reconstruction.

Using bit planes 7 through 0.

Learning observation: Using all eight planes gives an exact reconstruction. Using fewer planes produces an approximation because the omitted lower-order bits are not included.

15. References and Study Materials

The following references provide additional explanations of bit-plane decomposition, mathematical concepts and applications in Digital Image Processing.

📘 Reference 1: NPTEL – Bit Plane Slicing 📗 Reference 2: Digital Image Processing – Bit Plane Slicing Lecture Notes 📙 Reference 3: Digital Image Processing – Bit Plane Coding and Decomposition